DotDragnet
May 24, 2012, 05:41:54 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Mobile users - Our forum is Tapatalk enabled. http://www.tapatalk.com/
 
   Home   Help Search Login Register  
Pages: [1]   Go Down
  Print  
Author Topic: Regex help  (Read 172 times)
sarahA
DDN Contribs
Hero Member
*****
Posts: 2184



View Profile WWW Awards
« on: July 21, 2011, 10:20:14 AM »

I'm trying to write a regex to pull everything out within an anchor tag, which may include other tags eg.

<a href="blah.php" title="meh">(some text here)</a>
<a href="blah.php" title="more meh">(<span>more text</span>)</a>

basically everything within the brackets above.

I've used <a href="([^"])" title="([^"])">(.*)</a> however as I have more than one link in the variable that I'm going through, the .* is of course getting everything until the final closing anchor tag.

I can't just use a [^<] as there may be a different tag in there that I still need as with my example above. Any suggestions as to how to say 'everything until you reach a </a>' ?

Thanks muchly smile
Logged

JasonD
Global Moderator
Hero Member
*****
Posts: 551



View Profile Awards
« Reply #1 on: July 21, 2011, 01:58:39 PM »

$regex = '/<a href="([^"]*)" title="([^"]*)">(.*?)<\/a>/s';
Logged
sarahA
DDN Contribs
Hero Member
*****
Posts: 2184



View Profile WWW Awards
« Reply #2 on: July 21, 2011, 02:04:53 PM »

Thanks Jason I'll give that a try smile
Logged

Pages: [1]   Go Up
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF | SMF © 2006-2008, Simple Machines Valid XHTML 1.0! Valid CSS!