Avatar of skij
skij
Flag for Canada

asked on 

JavaScript/REGEX: Replace the 3rd match

Using JavaScript and Regular Expressions, how can I replace the third match?

For example, I want JavaScript to return this:
hello[11][22][X][44][55]'
var str = 'hello[11][22][33][44][55]';
alert( str.replace(/(\[[0-9]+\]){3}/, '[X]')  );

Open in new window

JavaScriptRegular Expressions

Avatar of undefined
Last Comment
skij

8/22/2022 - Mon