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
上一篇:Codeforces441A_Valera and Antique Items(水题)


下一篇:python用,进行多变量赋值