I am attempting to extract an entire paragraph from a text file using JavaScript and then display it in an HTML element. Despite reading numerous posts and articles, I have been unable to find the correct regex formula. Here is an excerpt from the text 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
The portion I need to extract is from "Starting test: Connectivity" until "passed test Connectivity." This is the JavaScript code snippet I am currently using:
`
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 current implementation, I only retrieve the first line of the paragraph. I initially thought that the wildcard operator would help with this issue, but including the word Connectivity in the regex pattern as below does not yield any results:
let connectivity = dcDiag.match(/Starting test: Connectivity[\n\r]+$(.*)Connectivity (/gm) || [];
In other programming languages, I would use a "text beginning * text ending" approach to extract the paragraph, however, it seems different in JavaScript. Since I am working on intranet servers without internet access, I prefer not to download jQuery and stick to vanilla JS only.