Skip to content

Instantly share code, notes, and snippets.

@tenbits
Last active December 17, 2015 21:19
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 tenbits/5673578 to your computer and use it in GitHub Desktop.
Save tenbits/5673578 to your computer and use it in GitHub Desktop.
string to regexp
RegExp.fromString = function(str, flags) {
return new RegExp(str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&"), flags);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment