Last active
December 17, 2015 21:19
-
-
Save tenbits/5673578 to your computer and use it in GitHub Desktop.
string to regexp
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
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