Weird Javascript Regex Replace Backreference Behavior

Posted by arshaw on Stack Overflow See other posts from Stack Overflow or by arshaw
Published on 2010-03-18T00:42:31Z Indexed on 2010/03/18 0:51 UTC
Read the original article Hit count: 365

Filed under:
|

why does the following js expression:

"test1 foo bar test2".replace(/foo.bar/, "$'")

result in the following string?

"test1  test2 test2"

is the $' in the replace string some sort of control code for including everything after the match???

this behavior was screwing with me most of the day. can anyone explain this?

thanks a lot

ps- this is the case in all browsers i've tested

© Stack Overflow or respective owner

Related posts about regex

Related posts about JavaScript