searching number in body using jquery
i am trying to search all numbers (of digit开发者_JAVA技巧s 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);
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);
精彩评论