Javascript lastIndex 正则表达式的一个疑惑
看下面这段代码:
function test(s){
var reg = /./g;
console.log(reg.exec(s));
console.log(reg.lastIndex);
var reg = /./g;
console.log(reg.exec(s));
console.log(reg.lastIndex);
}
test("abcd");
test("efgh");
我以为输出的lastIndex的值应该都是1,但是实际上的输出如下:
a
1
a
1
f
2
f
2
感觉就像是在第二次调用test的时候第2行和第6行并没有产生新的正则表达式,其之前的属性lastIndex还保留着(lastIndex=1)。这有点不合常理,头疼中。。。。。。
function test(s){
var reg = /./g;
console.log(reg.exec(s));
console.log(reg.lastIndex);
var reg = /./g;
console.log(reg.exec(s));
console.log(reg.lastIndex);
}
test("abcd");
test("efgh");
我以为输出的lastIndex的值应该都是1,但是实际上的输出如下:
a
1
a
1
f
2
f
2
感觉就像是在第二次调用test的时候第2行和第6行并没有产生新的正则表达式,其之前的属性lastIndex还保留着(lastIndex=1)。这有点不合常理,头疼中。。。。。。
asp去掉html,保留img br p div的正则实现代码
'去掉html中的table代码FunctionOutTable(str)dima,resetre=newRegExpre.pattern="(?!img|br|p|div).*?"re.global=truea=strOutTable=re.replace(a,"")EndFunction
JavaScript 正则表达式解析
JavaScript的RegExp对象和String对象定义了使用正则表达式来执行强大的模式匹配和文本检索与替换函数的方法.在JavaScript中,正则表达式是由一个RegExp对象表
正则表达式轻松消除HTML代码
一、清楚内容中的Javsscript代码FunctionClearJSCode(originCode)Dimregsetreg=NewRegExpreg.Pattern="SCRIPT[^]*/SCRIPT"reg.IgnoreCase=Truereg.Global=TrueclearJSCode=reg.Replace(originCode,"")EndF