Nodejs Regexp Escape escape(text)

Here you can find the source of escape(text)

Method Source Code

RegExp.escape = function(text) {
  return text.replace(/[-[\]{}()*+?.,\\^$|#\s]/g, "\\$&");
};

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. escapeRegExp()
    String.prototype.escapeRegExp = function() {
      return this.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
    };
    
  3. escapeRegExp(string)
    String.prototype.escapeRegExp = function(str) {
      return str.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, "\\$&");
    
  4. escapeRegExp(string)
    function escapeRegExp(string) {
      return string.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
    
  5. escapeRegExp(string)
    helpers.escapeRegExp = function(string) {
      return string.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
    };