Solved

preg_match_all regex lookbehind pattern

Posted on 2010-11-17
2
327 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 500 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
how to create a scatter graph with straight lines 6 25
Calculate values in an array 18 32
html input type 3 21
How to keep line breaks when outputting data from database 4 13
Introduction HTML checkboxes provide the perfect way for a web developer to receive client input when the client's options might be none, one or many.  But the PHP code for processing the checkboxes can be confusing at first.  What if a checkbox is…
Things That Drive Us Nuts Have you noticed the use of the reCaptcha feature at EE and other web sites?  It wants you to read and retype something that looks like this.Insanity!  It's not EE's fault - that's just the way reCaptcha works.  But it is …
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
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…

948 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now