修饰符
String.match
String 对象下函数,返回匹配到的字符串,未匹配到返回null。
- /data/i 不区分大小写匹配
var str = "Visit RUnoob";
var patt1 = /runoob/i;
document.write(str.match(patt1));
// RUnoob
- /data/g 全文检索
var str="Is this all there is?";
var patt1=/is/g;
document.write(str.match(patt1));
// is,is
- /data/gi 全文检索并不区分大小写
var str="Is this all there is?";
var patt1=/is/gi;
document.write(str.match(patt1));
// Is,is,is
test function
正则对象下函数,返回true Or false。
test()方法搜索字符串指定的值,根据结果并返回真或假。
exec function
正则对象下函数,返回匹配到的字符串,未匹配到返回null。