I didn't realize that you need a scripting host version 5.5 or greater for it to work. There was a snippet at msdn that did a test for the version before executing their sample, so I upgraded my scripting host. I also added a check for the version in my regular expression test application (http://www.geocities.com/udeleng/regex.htm).
Try it out and let me know of any bugs.
Thanks.
I ran it in Windows Script Host 5.6 and it worked fine:
var source = "this is sample text test123 this is sample text test456 this
is sample text test789 old "
var re = /test\d{3}/gi
WScript.Echo(re.exec(source))
WScript.Echo(re.exec(source))
WScript.Echo(re.exec(source))
WScript.Echo(re.exec(source))
output:
test123
test456
test789
null
What version of JScript or which browser are you using?
I am trying to get the results of a regular expression search on a string. I
thought that execting the EXEC method successively will return the results,
but it didn't.
Here is what I have,
var source = "this is sample text test123 this is sample text test456 this
is sample text test789 old "
var re = /test\d{3}/gi
alert(re.exec(source))
alert(re.exec(source))
alert(re.exec(source))
alert(re.exec(source))
I expected the following alert messages: test123, test456, test789, null
but I got this: test123, test123, test123, test123
What am I doing wrong?
Thanks.