Solved

preg_match_all regex lookbehind pattern

Posted on 2010-11-17
2
336 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

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

Whatever be the reason, if you are working on web development side,  you will need day-today validation codes like email validation, date validation , IP address validation, phone validation on any of the edit page or say at the time of registration…
This article discusses four methods for overlaying images in a container on a web page
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

632 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