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
Solved

preg_match_all regex lookbehind pattern

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Wordpress Pagination Function Not working ? 7 39
What does this formatting equate to? 7 18
Email called spam 5 36
Ahax pagination 9 33
This article discusses four methods for overlaying images in a container on a web page
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

828 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