Last active
September 10, 2019 21:41
-
-
Save ezirmusitua/655a60c7261bf3c01f8ca9541d89fdfd to your computer and use it in GitHub Desktop.
[Escape regex special characters] escape regex special characters with /, using in search #regex #javascript #node
This file contains hidden or 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
function escapeRegExp(text) { | |
return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, '\\$&'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment