欢迎来到DIVCSS5查找CSS资料与学习DIV CSS布局技术!
test()
test()方法搜索字符串指定的值,根据结果并返回真或假。
 
下面的示例是从字符串中搜索字符 "e" :
 
实例
var patt1=new RegExp("e");
document.write(patt1.test("The best things in life are free"));
由于该字符串中存在字母 "e",以上代码的输出将是:
 
true
 
 
当使用构造函数创造正则对象时,需要常规的字符转义规则(在前面加反斜杠 \)
 
实例
var re = new RegExp("\\w+");

如需转载,请注明文章出处和来源网址:http://www.divcss5.com/html/h65060.shtml