Regular expression 
Author Message
 Regular expression

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.



Wed, 08 Sep 2004 01:07:20 GMT  
 Regular expression
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.



Wed, 08 Sep 2004 03:34:03 GMT  
 Regular expression

I tried it on IE 4, 5, and 5.5

  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.



Wed, 08 Sep 2004 04:10:16 GMT  
 Regular expression

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.



Wed, 08 Sep 2004 05:09:45 GMT  
 
 [ 4 post ] 

 Relevant Pages 

1. Split string by regular expression (ie. date)

2. Regular Expression Problems

3. Help, really simple question w/ Regular Expressions

4. A regular expression - a challenge to yall !

5. regular expression

6. A cunning regular expression!

7. Regular Expression Needed

8. Using regular expressions

9. Regular Expression matching

10. MS's Regular Expression component is flawed?

11. Regular Expressions in ASP

12. Regular Expressions problem

 

 
Powered by phpBB® Forum Software