Home  >  Article  >  Web Front-end  >  Prototype RegExp对象 学习_prototype

Prototype RegExp对象 学习_prototype

WBOY
WBOYOriginal
2016-05-16 18:49:56970browse
复制代码 代码如下:

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

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


就一个escape方法,就是把那几个特殊字符转义一下。
还有就是match方法是test方法的别名。
看一个例子:
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