Last active
August 29, 2015 14:18
-
-
Save Alex1990/14b8ca51a88362695ca7 to your computer and use it in GitHub Desktop.
Escape regexp special characters.
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
| /** | |
| * Escape regexp special characters. The slash `/` will be escaped automatically. | |
| * http://stackoverflow.com/questions/494035/how-do-you-pass-a-variable-to-a-regular-expression-javascript/494122#494122 | |
| */ | |
| function escapeRegexp(str) { | |
| return str.replace(/[.*+?^$|[\](){}\\-]/g, '\\$&'); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment