以前使用的正则表达式。
/.*/.exec('meow')
{thingIforgot} [0] =='meo'
现在我知道上面的表达式会返回结果。我特意想记住我不能谷歌的变量名称。
==============================
while((carry = /{[^%]\/*?\}/.exec(string))){
var _results
if(/\{s\d+\}/.exec(carry[0])){
} else
if(/\{s\d+\}/.exec(carry[0])){
} else{
throw new Error('MARLFOREMD STRING '+string)
}
我知道我不必分配那个表达式= /
答案 0 :(得分:0)
我相信您可能正在寻找一些已弃用的Firefox功能:
Gecko 8.0 note(Firefox 8.0 / Thunderbird 8.0 / SeaMonkey 2.5)
在Gecko 8.0之前(Firefox 8.0 / Thunderbird 8.0 / SeaMonkey 2.5),exec() 实施不正确;当它被调用时没有参数,它 将匹配前一个输入的值(RegExp.input property)而不是字符串“undefined”。这是固定的; 现在/undefined/.exec()正确导致['undefined'],而不是 错误。
答案 1 :(得分:0)
与其他一些语言especially Perl不同,JavaScript / ECMAScript没有与RegExp匹配相关的全局变量。
有关上一场比赛的信息仅存储在返回的值/集合和属性on the RegExp
itself中:
var pattern = /./g;
var found = pattern.exec('a');
console.log(found[0], found.index, pattern.lastIndex); // "a", 0, 1
但是,请注意lastIndex
只会增加“全球”RegExp
:
var pattern = /{[^%]\/*?\}/g;
// ^
while((carry = pattern.exec(string))){
// ...
}
您可以看到.exec()
in the spec所做的一切。