RegExp实例方法:
1、Test()
RegExpObject.test(string)
判断string中是否有与表达式匹配的字符串,有则返回true,否则返回false
例如
var patt1=new RegExp("e");
document.write(patt1.test("The best things in life are free"));
由于该字符串中存在字母 "e",以上代码的输出将是:true
2、exec()
RegExpObject.exec(string)
exec() 方法检索字符串中的指定值。返回值是被找到的值。如果没有发现匹配,则返回 null。
例如
JScript 代码
复制


var str= "cat2,hat8" ;

var reg=/c(at)\\d/ ; 有分组

console.info(reg.exec(str));//运行返回 ["cat2", "at"]
网址链接:http://www.studyofnet.com/news/662.html