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")}))
2.1m questions
2.1m answers
60 comments
57.0k users