I\'m trying to find a way to replace nth match of more matches lite this.
string = \"one two three one one\"
How do I target the se
Update :
To make it dynamic use this:
((?:.*?one.*?){1}.*?)one
where the value 1 means (n-1); which in your case is n=2
and replace by:
$1\(one\)
Regex101 Demo
const regex = /((?:.*?one.*?){1}.*?)one/m;
const str = `one two three one one asdfasdf one asdfasdf sdf one`;
const subst = `$1\(one\)`;
const result = str.replace(regex, subst);
console.log( result);