I'm trying to extract an entire paragraph from a txt file using JS, then put it to an html element. I've read quite a few posts already and articles, but I can't get the right regex formula. This is an extract of the txt file:
Doing initial required tests
Testing server: xxxxxxxx\yyyyyyyy
Starting test: Connectivity
* Active Directory LDAP Services Check
Determining IP4 connectivity
* Active Directory RPC Services Check
......................... yyyyyyyy passed test Connectivity
Doing primary tests
What I need to extract is from "Starting test: Connectivity" until "passed test Connectivity". This is the JS code I'm trying:
`
async function getText(file) {
let dcdiagFile = await fetch(file);
let dcDiag = await dcdiagFile.text();
let connectivity = dcDiag.match(/Starting test: Connectivity[\n\r]+$(.*)(/gm) || [];
document.getElementById("DNS").innerHTML = connectivity;
console.log(connectivity);
}
getText("./dcdiagreport.txt");
` With my code I only get the first line. I've thought that the wild card would address that, but if I add the word Connectivity as in below:
let connectivity = dcDiag.match(/Starting test: Connectivity[\n\r]+$(.*)Connectivity (/gm) || [];
I don't get anything. In other programming languages I would go with "Text beginning * text ending" the paragraph. But not in JS. It's an intranet internetless servers and preferibly I don't want to download jquery. Vanilla JS only.