你这样用根本就没打算用()匹配到的内容.
写法也有些不妥,可以改为:
/.*((fox|dog) and (cat|mouse) and (dog|mouse) and (cat|dog) and (fox|(mouse)).*/gi;
功能应该是一样的.一般来说,$1-9已经够用了.
如果你想使用每次匹配得到的$i结果,建议你使用replace方法
写法也有些不妥,可以改为:
/.*((fox|dog) and (cat|mouse) and (dog|mouse) and (cat|dog) and (fox|(mouse)).*/gi;
功能应该是一样的.一般来说,$1-9已经够用了.
如果你想使用每次匹配得到的$i结果,建议你使用replace方法
这样写, 括号就没分配 $n 之类的匹配结果.
$20: m[20]另外,在replace 的时候,也可以使用 $20 这样的用法的。
function MatchDemo()
{
var r, re;
var s = " aa bb cc fox and cat and mouse and dog and fox dd eeee ";
re = /.*(?:(?:(?:fox)|(?:dog)) and (?:(?:cat)|(?:mouse)) and (?:(?:dog)|(?:mouse)) and (?:(?:cat)|(?:dog)) and (?:(?:fox)|(?:mouse))).*/gi;
if( re.test( s ) )
{
alert( RegExp.$10 )
}
}MatchDemo() ;
{
alert(m[10]);
}