Nodejs Regexp Escape escapeRegExp(string)

Here you can find the source of escapeRegExp(string)

Method Source Code

helpers.escapeRegExp = function(string) {
   return string.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
};

Related

  1. escape()
    function escapeRegExp(str) {
        return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
    function unEscapeRegExp(str) {
        return str.replace(/\\(?!\\)/g,'');
    RegExp.escape = escapeRegExp;
    RegExp.prototype.escape = function(){
        var flags = (this.global ? 'g' : '') + (this.ignoreCase ? 'i' : '') + (this.multiline ? 'm' : ''); 
    ...
    
  2. escape(text)
    RegExp.escape = function(text) {
      return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
    };
    
  3. escapeRegExp()
    String.prototype.escapeRegExp = function() {
      return this.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
    };
    
  4. escapeRegExp(string)
    String.prototype.escapeRegExp = function(str) {
      return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
    
  5. escapeRegExp(string)
    function escapeRegExp(string) {
      return string.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");