First, I have:
const regEx = /(?:\S+\s)?\S*text\S*(?:\s\S+)?/;
const fullText = "one two text three four";
console.log(fullText.match(regEx));
which results in
[ 'two text three', index: 4, input: 'one two text three four' ]
Then I have:
const regEx2 = new RegExp("(?:\S+\s)?\S*text\S*(?:\s\S+)?", "g");
const fullText2 = "one two text three four";
console.log(fullText2.match(regEx2));
which results in:
[ 'text' ]
Using new RegExp
, how do I get the same result as the first block of code?