Last active
February 2, 2016 06:28
-
-
Save vko-online/fd32ae881c4ced2c82ad to your computer and use it in GitHub Desktop.
JavaScript safe regexp queries when using MongoDB database
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
//remove dangerous symbols | |
function safeRegexp(query) { | |
return query.replace(/([.?*+^$[\]\\(){}|-])/g, '\\$1'); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment