Skip to content

Instantly share code, notes, and snippets.

@andreineculau
Created April 25, 2013 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andreineculau/5459906 to your computer and use it in GitHub Desktop.
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
re:replace(Str, "[\\-\\[\\]\\/\\{\\}\\(\\)\\*\\+\\?\\.\\,\\\\\^\\$\\|\\#\\s\\&]", "\\\\&", [global]).
str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\,\\\^\$\|\#\s]/g, '\\$&')
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment