@Belinda
2015-04-23T02:51:20.000000Z
字数 413
阅读 1170
实习笔记
RegExp 对象用于规定在文本中检索额内容。
RegExp 对象有 3 个方法:test()、exec() 以及 compile()。
test(),用于检索字符中的指定值,返回 false 或 true。
exec(),用于检索字符中的指定值,返回被找到的值,如果没有被找到,返回null。
compile()
compile() 方法用于改变 RegExp。
compile() 既可以改变检索模式,也可以添加或删除第二个参数。
var patt1=new RegExp("e"); document.write(patt1.test("The best things in life are free")); patt1.compile("d"); document.write(patt1.test("The best things in life are free"));
由于字符串中存在 "e",而没有 "d",以上代码的输出是: