Here is the case: I want to find the elements which match the regex...
targetText = \"SomeT1extSomeT2extSomeT3extSomeT4extSomeT5extSomeT6ext\"
I kept getting infinite loops while following the advice above, for example:
var reg = /e(.*?)e/g;
var result;
while((result = reg.exec(targetText)) !== null) {
doSomethingWith(result);
}
The object that was assigned to result
each time was:
["", "", index: 50, input: "target text", groups: undefined]
So in my case I edited the above code to:
const reg = /e(.*?)e/g;
let result = reg.exec(targetText);
while(result[0] !== "") {
doSomethingWith(result);
result = reg.exec(targetText);
}