到目前为止,我在尝试在javascript匹配中使用多个反向引用时遇到了麻烦:-
function newIlluminate() {
var string = "the time is a quarter to two";
var param = "time";
var re = new RegExp("(" + param + ")", "i");
var test = new RegExp("(time)(quarter)(the)", "i");
var matches = string.match(test);
$("#debug").text(matches[1]);
}
newIlluminate();
#Debug匹配正则表达式're'时会打印'time',这是param的值。
我已经看到了匹配示例,其中通过将匹配条件用括号括起来使用了多个反向引用,但是我的(time)(quarter)...的匹配返回null。
我要去哪里错了?任何帮助将不胜感激!
您的正则表达式实际上是在寻找timequarterthe
匹配并将匹配项(如果找到)分成三个反向引用。
我认为您的意思是:
var test = /time|quarter|the/ig;
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句