SoFunction
Updated on 2025-04-14

Prototype RegExp Object Learning

Copy the codeThe code is as follows:

= ;

= function(str) {
return String(str).replace(/([.*+?^=!:${}()|[\]\/\\])/g, '\\$1');
};


Just one escape method is to escape those special characters.
Also, the match method is an alias for the test method.
See an example:
var str=("+.[]$://!");
(str) //==> "\+\.\[\]\$\:\/\/\!"