Skip to content

Instantly share code, notes, and snippets.

@yamadapc
Created March 13, 2014 20:28
Show Gist options
  • Save yamadapc/9536334 to your computer and use it in GitHub Desktop.
Save yamadapc/9536334 to your computer and use it in GitHub Desktop.
'use strict';
var escapedCharsRegExp = /([.?*+^$[\]\\(){}|-])/g;
function escapeRegExp(str) {
return str && str.replace && str.replace(escapedCharsRegExp, '\\$1');
}
function safeRegExp(str) {
return new RegExp(escapeRegExp(str));
}
exports = module.exports = escapeRegExp;
exports.safeRegExp = safeRegExp;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment