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