javaScript高级教程(八)-----正则表达式温故知新

1.RegExp对象:五个属性二个方法

五个属性:global, ignoreCase,multiline,lastIndex,source

二个方法:

exec()--模式匹配

test()--检测一个字符串是否含有某个模式

2.例子

var pattern = /\bJava\w*\b/g;
var text = 'JavaScript is more fun than Java or JavaBeans!';
var result;
while((result = pattern.exec(text)) != null){
  console.log('Matched! '+result[0] +' at position '+result.index +' next search begins at position '+pattern.lastIndex);
  
}
//结果
Matched! JavaScript at position 0 next search begins at position 10
Matched! Java at position 28 next search begins at position 32
Matched! JavaBeans at position 36 next search begins at position 45

 

 

posted @ 2013-08-24 03:44  等风来。。  Views(229)  Comments(0Edit  收藏  举报
------------------------------------------------------------------------------------------------------------ --------------- 欢迎联系 x.guan.ling@gmail.com--------------- ------------------------------------------------------------------------------------------------------------