this is my first question. This has stumped me for 2 days. I have a list of items, and I need to grab all matches that contain this pattern MM/DD/YYYY … http://www.someurl.com. I am using jquery and here is what I have now. It is alerting only once when I am expecting it to alert 3 times.
$('#news').parent().find('td').children('span.srNewsBlurb').each(function() {
var html = $(this).html();
if(/(0?[1-9]|1[012])\/(0?[1-9]|[12][0-9]|3[01])\/(.*http.*)/i.test(html)){
alert('this works');
}
});
here is the content…
Toys R Us Open Through Christmas Eve (68%)
01/05/2012 – NEW YORK (http://www.thestreet.com/story/11353279/1/toys-r-us-open-through-christmas-eve.html) — It’s time to squeeze in more midnight shopping. similar results
Jeanine Skowronski
Cities Adding the Most Jobs in 2011 (68%)
01/05/2012 – NEW YORK (http://www.thestreet.com/story/11351046/1/cities-adding-the-most-jobs-in-2011.html) — Much of the country is still waiting for the economic recovery to lift the local job market, but in San Antonio it’s as though the recession never similar results
Seth Fiegerman
Congress’ Approval Rating Hits All-Time Low (68%)
01/05/2012- NEW YORK (http://www.thestreet.com/story/11353209/1/congress-approval-rating-hits-all-time-low.html) — Just when it seemed it couldn’t get any worse, Congress’ approval ratings have hit a new low. similar results
Seth Fiegerman
I would engage in a little code reorg: The find/children construct is extremely awkward, and I would re-label my HTML to not require wandering around the parent structure. That said, I suspect your problem is one of those fundamental issues with RegExp, because this worked for me:
See that
((.|\s)*)construct toward the end of the regular expression? Javascript regular expressions are weird in that they match carriage return/line feeds via the\soperator, but not the.operator. So if your HTML has raw line feeds in it, you need to use this expression. Also, building the regexp once and then using it over and over is much more efficient than re-invoking the RegExp constructor every interation.