当前位置:Gxlcms > JavaScript > PrototypeRegExp对象学习_prototype

PrototypeRegExp对象学习_prototype

时间:2021-07-01 10:21:17 帮助过:8人阅读

代码如下:

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) //==> "\+\.\[\]\$\:\/\/\!"

人气教程排行