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

 

 

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2021-06-07
  • 2022-12-23
  • 2021-11-19
  • 2021-07-21
  • 2021-12-09
猜你喜欢
  • 2021-06-05
  • 2021-06-24
  • 2022-02-23
相关资源
相似解决方案