Home >Web Front-end >JS Tutorial >Prototype RegExp object learning_prototype

Prototype RegExp object learning_prototype

WBOY
WBOYOriginal
2016-05-16 18:49:561040browse
Copy code The code is as follows:

RegExp.prototype.match = RegExp.prototype.test;

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


Just an escape method, which is to escape those special characters.
Also, the match method is an alias of the test method.
Look at an example:
var str=RegExp.escape(" .[]$://!");
document.writeln(str) //==> " .[]$: //!"
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn