日期:2014-05-16  浏览次数:20349 次

js 重新学习笔记( 六 ) 正则表达式

?

1, RegExp 正则表达式对象?

?

? ? test 方法测试字符串中有没有指定的字符 ,返回 true 或false

?

var patt1=new RegExp("e");

document.write(patt1.test("The best things in life are free")); 

由于字符串中包含"e" 返回 true 
??

2, ?exec 方法寻找字符串中指定的值, 找到了就返回该值 ,没找到就 返回null?

?

var patt1=new RegExp("e");

document.write(patt1.exec("The best things in life are free")); 
由于该字符串中存在字母 "e",以上代码的输出将是:
e

?

? ?var patt1 =new RegExp("","") ; 也可以有第二个参数 .?

?

? ?更多的请看REG 对象参考手册

?

? ?http://www.w3school.com.cn/js/jsref_obj_regexp.asp

?

?

?

?

?

?