Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

preg_match_all regex lookbehind pattern

Posted on 2010-11-17
2
Medium Priority
?
340 Views
Last Modified: 2012-08-14
This question is related to question http://www.experts-exchange.com/Web_Development/Web_Languages-Standards/PHP/Q_26620121.html?cid=239#a34151863

As I explained before I'm parsing the html of an auction page I got help from an expert as to how to do a lookahead regex so I could grab the title of the auction only if the item is sold.

Now I'm running in the same situation because I need to grab the auction end date but again only if the item is sold, my problem is the date come after the sold flag in the source code.

an example of the data to parse

<td class=\"bids bin1\">0 Bids</td><td class=\"prc binsold g-b\">$19.99</td><td class=\"tme  rt\"><b class=\"hidlb\">End Date:</b><span>Nov-15 19:00</span></td>

<td class=\"bids\"><div class=\"bin1\">7 Bids</div><span class=\"sold\">Sold</span></td><td class=\"prc bidsold g-b\">$55.32</td><td class=\"tme  rt\"><b class=\"hidlb\">End Date:</b><span>Nov-15 19:00</span></td>

As can be seen in the example an unsold item does not have the "<span class=\"sold\">Sold</span>" string

preg_match_all is a must because there is multiple lines to be parse.


0
Comment
Question by:gamebits
2 Comments
 
LVL 48

Accepted Solution

by:
hernst42 earned 2000 total points
ID: 34154267
Try this regexp:
$match_count = preg_match_all('#<span\s+class\s*=\s*"sold">.*End Date:</b><span>([^<]+)</span></td>#Uis',$sourcestring,$matches);

Open in new window

0
 
LVL 28

Author Closing Comment

by:gamebits
ID: 34154299
Right on the money, awesome, you the man.

Thanks
0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses four methods for overlaying images in a container on a web page
This article discusses how to create an extensible mechanism for linked drop downs.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.
Suggested Courses

963 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question