J
jasonkester
Just a heads up for anybody that comes across this in the future.
Noticed a strange behavior in RegExp.test() today. Check out the
following code. It will alternately display "chokes" and null, as
every second call to .test() fails.
<script>
var str = "RegExp (chokes) on this every 2nd time";
var re = /chokes/g;
for (var a=0; a<10; a++)
{
alert(re.exec(str));
}
</script>
Remove the "g" from the end of the RegExp and it works as expected.
The "g" switch instructs the regex to perform global matching, which
shouldn't affect the testing for a single run. Anybody care to venture
an explaination for why this might have the demonstrated effect?
Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/
Noticed a strange behavior in RegExp.test() today. Check out the
following code. It will alternately display "chokes" and null, as
every second call to .test() fails.
<script>
var str = "RegExp (chokes) on this every 2nd time";
var re = /chokes/g;
for (var a=0; a<10; a++)
{
alert(re.exec(str));
}
</script>
Remove the "g" from the end of the RegExp and it works as expected.
The "g" switch instructs the regex to perform global matching, which
shouldn't affect the testing for a single run. Anybody care to venture
an explaination for why this might have the demonstrated effect?
Jason Kester
Expat Software Consulting Services
http://www.expatsoftware.com/