For example:
'abcjkjokabckjk'.replace('/(abc)/g',...)
If I want to replace a specify position 'abc', what I can do?
Like this:
Use RegExp constructor to pass variables inside regex.
RegExp
var s = 'abcjkjokabckjk' search = 'abc' var n = 2 alert(s.replace(RegExp("^(?:.*?abc){" + n + "}"), function(x){return x.replace(RegExp(search + "$"), "HHHH")}))
1.4m articles
1.4m replys
5 comments
57.0k users