views:

17

answers:

1

i am trying to search all numbers (of digits 8) in body using jQuery, its only returning first no. in body?

var myRe = /[0-9]{8}/;  
var myArray = myRe.exec($('body').html());  
alert(myArray);
+3  A: 

Add the g or 'global' flag to the regular expression. Now instead of using exec() which only returns the first match, call match() on the string itself, which returns an array of all results:

var myRe = /[0-9]{8}/g;
var myArray = $('body').html().match(myRe);
Ryan Tenney
Did this resolve the problem? If so, please be sure to mark the answer "accepted", that way we both get some reputation.
Ryan Tenney