Prototype RegExp对象 学习


复制代码 代码如下:

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) //==> "\+\.\[\]\$\:\/\/\!"
« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3