esamattis / esamattis/underscore.string

replaceAll treats key as regex

Open
#461 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
3.4k
Forks
367
PR merge metrics
No merged PRs in 30d

Description

`replaceAll` should not treat its second parameter as a regex.

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

but

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

See also [a stackoverflow discussion](http://stackoverflow.com/questions/1144783/replacing-all-occurrences-of-a-string-in-javascript) which suggests using the regex escape function presented [here](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Guide/Regular_Expressions#Using_Special_Characters).

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

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.