-4

以前使用的正则表达式。

/.*/.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)
    }

我知道我不必分配那个表达式 = /

4

2 回答 2

0

Unlike a few other languages, especially Perl, JavaScript/ECMAScript does not have global variables associated with RegExp matching.

The information about the previous match is stored only in the returned value/collection and in properties on the RegExp itself:

var pattern = /./g;
var found = pattern.exec('a');

console.log(found[0], found.index, pattern.lastIndex); // "a", 0, 1

Though, note that the lastIndex will only increment for "global" RegExp:

var pattern = /{[^%]\/*?\}/g;
//                         ^

while((carry = pattern.exec(string))){
    // ...
}

You can see everything that .exec() does in the spec.

于 2013-10-09T07:53:03.833 回答
0

我相信您可能正在寻找一些已弃用的 Firefox 功能:

Gecko 8.0 注意 (Firefox 8.0 / Thunderbird 8.0 / SeaMonkey 2.5)

在 Gecko 8.0 (Firefox 8.0 / Thunderbird 8.0 / SeaMonkey 2.5) 之前,exec() 的实现不正确;当它在没有参数的情况下被调用时,它将与前一个输入的值(RegExp.input 属性)匹配,而不是与字符串“undefined”匹配。这是固定的;现在 /undefined/.exec() 正确地导致 ['undefined'],而不是错误。

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/RegExp/exec#Calling_exec()_with_no_parameters_in_old_Gecko_versions

于 2013-10-09T07:44:13.560 回答