Created
April 25, 2013 13:57
-
-
Save andreineculau/5459906 to your computer and use it in GitHub Desktop.
Escape strings so that they are not treated as Regular Expressions
JavaScript, Erlang
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
re:replace(Str, "[\\-\\[\\]\\/\\{\\}\\(\\)\\*\\+\\?\\.\\,\\\\\^\\$\\|\\#\\s\\&]", "\\\\&", [global]). |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\,\\\^\$\|\#\s]/g, '\\$&') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment