PHP RegEx Matching Partial Data

I am trying parse the ESPN bottom line feed using RegEx but am coming up a bit short. Instead of it getting all of the NFL games it is only getting about half.

This is the data returned by ESPN.

 &nfl_s_delay=120&nfl_s_stamp=0909064837&nfl_s_left1=^Dallas 24   NY Giants 17 (FINAL)&nfl_s_right1_count=0&nfl_s_url1= at Chicago (1:00 PM ET)&nfl_s_right2_count=0&nfl_s_url2= at Cleveland (1:00 PM ET)&nfl_s_right3_count=0&nfl_s_url3= Louis at Detroit (1:00 PM ET)&nfl_s_right4_count=0&nfl_s_url4= England at Tennessee (1:00 PM ET)&nfl_s_right5_count=0&nfl_s_url5= at Kansas City (1:00 PM ET)&nfl_s_right6_count=0&nfl_s_url6= at Minnesota (1:00 PM ET)&nfl_s_right7_count=0&nfl_s_url7= at New Orleans (1:00 PM ET)&nfl_s_right8_count=0&nfl_s_url8= at NY Jets (1:00 PM ET)&nfl_s_right9_count=0&nfl_s_url9= at Houston (1:00 PM ET)&nfl_s_right10_count=0&nfl_s_url10= Francisco at Green Bay (4:25 PM ET)&nfl_s_right11_count=0&nfl_s_url11= at Arizona (4:25 PM ET)&nfl_s_right12_count=0&nfl_s_url12= at Tampa Bay (4:25 PM ET)&nfl_s_right13_count=0&nfl_s_url13= at Denver (8:20 PM ET)&nfl_s_right14_count=0&nfl_s_url14= at Baltimore (7:00 PM ET)&nfl_s_right15_count=0&nfl_s_url15= Diego at Oakland (10:15 PM ET)&nfl_s_right16_count=0&nfl_s_url16=

I am using two RegEx patterns, one to catch games that are completed/in progress:

preg_match_all('/nfl_s_left\d{1,2}=\^?(?P<awayteam>[a-zA-Z]+(?:\s+[a-zA-Z]+)*)\s+(?P<awayscore>\d+)\s+\^?(?P<hometeam>[a-zA-Z]+(?:\s+[a-zA-Z]+)*)\s+(?P<homescore>\d+)\s+(?P<time>\(.*?\))/', $content, $matches_in_progress, PREG_SET_ORDER);

And another to catch games that haven't started yet:

preg_match_all('/nhl_s_left\d=\^?(?P<awayteam>[a-zA-Z]+(?:\s+[a-zA-Z]+)*)\s+(at)+\s+\^?(?P<hometeam>[a-zA-Z]+(?:\s+[a-zA-Z]+)*)\s(?P<time>\(.*?\))/', $content, $matches_upcoming, PREG_SET_ORDER);

Only 8 of the 16 games match, and I can't figure out why. The matches for this week are Dallas at NY Giants, Philadelphia at Cleveland, New England at Tennessee, Atlanta at Kansas City, Jacksonville at Minnesota, Washington at New Orleans, and Buffalo at NY Jets.

I'd very much appreciate any help getting my RegEx to match all 16 games for this week and weeks to come.

Edit: Modified string to match, forgot that I strip %20 before applying RegEx to it.


Your regular expressions are very complicated. Since the original string is encoded as URL arguments, you could use parse_str to get a key => value array. Then use regular expressions to find the entries you want.

$string = "&nfl_s_delay=120&nfl_s_stamp=0909054449&nfl_s_left1=^Dallas%2024%20%20%20NY%20Giants%2017%20(FINAL)&nfl_s_right1_count=0&nfl_s_url1=";
parse_str($string, $array);

Found the error. I did not have d{1,2} in the 2nd regex to match games 10-16. And I also didn't have +(?:\.*) which forced St. Louis to be skipped over.

My new, working RegEx is:


Need Your Help

Idiomatic way to implement generic functions in Go

generics reflection go covariance

Let's say I want to write a function to check whether a predicate is matched for an element in a slice:

iText: List of images in a cell

java pdf itext

I would like to create a table that has a list of dots. I don't know ahead of time how many dots I have, but if they overflow the cell, I want them to wrap, just like text would. My code is somet...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.