underscore.string icon indicating copy to clipboard operation
underscore.string copied to clipboard

replaceAll treats key as regex

Open mpartel opened this issue 9 years ago • 0 comments

replaceAll should not treat its second parameter as a regex.

    "1$a2".replace('$a', 'b');  // => "1b2" as expected

but

    s("1$a2").replaceAll('$a', 'b').value();  // => "1$a2" but should be "1b2"

See also a stackoverflow discussion which suggests using the regex escape function presented here.

It might be nice to add the regex escape function to this library too.

mpartel avatar Nov 05 '15 01:11 mpartel