首先,为我糟糕的英语道歉.
我正在尝试测试字符串以匹配模式,所以我写了这个:
var str = 'test';
var pattern = new RegExp('te', 'gi'); // yes, I know that simple 'i' will be good for this
Run Code Online (Sandbox Code Playgroud)
但我有这个意想不到的结果:
>>> pattern.test(str)
true
>>> pattern.test(str)
false
>>> pattern.test(str)
true
Run Code Online (Sandbox Code Playgroud)
有谁能解释一下?