RegExp实例方法:html
一、Test()spa
RegExpObject.test(string)htm
判断string中是否有与表达式匹配的字符串,有则返回true,不然返回falseip
例如字符串
var patt1=new RegExp("e"); string
document.write(patt1.test("The best things in life are free")); it
因为该字符串中存在字母 "e",以上代码的输出将是:trueconsole
二、exec()class
RegExpObject.exec(string)test
exec() 方法检索字符串中的指定值。返回值是被找到的值。若是没有发现匹配,则返回 null。
例如
var str= "cat2,hat8" ;
var reg=/c(at)\\d/ ; 有分组
console.info(reg.exec(str));//运行返回 ["cat2", "at"]网址连接:http://www.studyofnet.com/news/662.html