I'm trying to find all the matches for 'test' in my string:
const search = "test";
const regexString = "(?:[^ ]+ ){0,3}" + "test" + "(?: [^ ]+){0,3}";
const re = new RegExp(regexString, "gi");
const matches = [];
const fullText = "my test string with a lot of tests that should match the test regex";
let match = re.exec(fullText);
while (match != undefined) {
matches.push(match[1]);
match = re.exec(fullText);
}
console.log(matches);
I'm getting the following:
[ undefined, undefined, undefined ]
Why isn't my search working?