Regex fine tuning again.

I'm building a small application to allow me to gather sell price on ebay, I divided the script in 5 different preg_match_all section, one for each of the 5 data I want to pull

1) title
2) item number
3) bids
4) price
5) date

with the help of other Experts here I've been able to filter only the sold items, everything work pretty good but there are a few glitches and my script needs some fine tuning, here is an example;

            $match_count1 = preg_match_all('#class\s*=\s*"vip">([^<]*)</a>(?=(?:.(?!class\s*=\s*"vip"))*<span\s+class\s*=\s*"sold">)#is',$source,$title_arr);
// print "<td><table border=1>";

 if ($match_count1>0)

foreach($title_arr[1] as $title)
        echo "<tr><td><input type=\"text\" name=\"title[]\" size=\"75\" value=\"".$title."\"></td>";

  print "No match found.";
This script allows me to get the title of an item, the line to scrape look like this

<a href=\"\" class=\"vip\">1969 O-PEE-CHEE HOCKEY #146 NORM FERGUSON PSA 9 MINT</a>

But if the sellers took the "bold" option than the line look like this

<a href=\"\" class=\"vip g-b\">1979 Topps #18 Wayne Gretzky Rookie HOF Oilers PSA 7</a>

Not a huge difference here were going from class=\"vip\" to class=\"vip g-b\"

So the question is how can I modify the preg_match_all regex to pickup both instance

LVL 28
Who is Participating?
käµfm³d 👽Connect With a Mentor Commented:
I believe changing it from




in the pattern will do it. Be sure to escape that quote if you need to.
Terry WoodsIT GuruCommented:
Try this:
$match_count1 = preg_match_all('#class\s*=\s*"vip( g-b)?">([^<]*)</a>(?=(?:.(?!class\s*=\s*"vip( g-b)?"))*<span\s+class\s*=\s*"sold">)#is',$source,$title_arr);

Open in new window

gamebitsAuthor Commented:
@TerryAtOpus I'm loosing everything else and for the title I should be getting all I have is g-b

@kaufmed Yep, that did it, awesome.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.