I get this behavior in both Chrome (Developer Tools) and Firefox (Firebug). Note the regex test returns alternating true/false values:
> var re = /.*?bl.*gr.*/gi;
undefined
> re
/.*?\bbl.*\bgr.*/gi
> re.test("Blue-Green");
true
> re.test("Blue-Green");
false
> re.test("Blue-Green");
true
> re.test("Blue-Green");
false
However, testing the same regex as a literal:
> /.*?bl.*gr.*/gi.test("Blue-Green");
true
> /.*?bl.*gr.*/gi.test("Blue-Green");
true
> /.*?bl.*gr.*/gi.test("Blue-Green");
true
> /.*?bl.*gr.*/gi.test("Blue-Green");
true
I can't explain this and it's making debugging very difficult. Can anyone explain this behavior?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…