Skip to content

Instantly share code, notes, and snippets.

@vko-online
Last active February 2, 2016 06:28
Show Gist options
  • Save vko-online/fd32ae881c4ced2c82ad to your computer and use it in GitHub Desktop.
Save vko-online/fd32ae881c4ced2c82ad to your computer and use it in GitHub Desktop.
JavaScript safe regexp queries when using MongoDB database
//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