• 0

regex question


Question

ok :ninja: i'm no pro at regular expressions or anything but this is what i have:

<\s*a\s*.*href\s*=\s*(?:\"(?<url>[^\"]*)\"|(?<url>\S+)).*>(?<name>.+)</a>

all i know is that it works, somewhat. it's for extracting links, and grouping the url + name. it only works with links that are like

link 1

link 2

link 3

doesn't work when they're all on one line like

link 1 link 2 link 3

how do i make it stop on the first </a> tag? for when i get links that are all on one line.

Link to comment
Share on other sites

8 answers to this question

Recommended Posts

  • 0

Woop nevermind, got it solved somewhat, using ?

&lt;\s*a\s*.*?href\s*=\s*(?:\"(?&lt;url&gt;[^\"]*)\"|(?&lt;url&gt;\S+?)).*?&gt;(?&lt;name&gt;.+?)&lt;/a&gt;

nevermind, fixed!

Edited by tommie
Link to comment
Share on other sites

  • 0

Nevermind again haha this regex stuff is interesting. Had another problem got that working though.

Edited by tommie
Link to comment
Share on other sites

  • 0

Ok well, 1 problem now:

&lt;\s*a\s*.*?href\s*=\s*(?:\"(?&lt;url&gt;[^\"]*)\"|(?&lt;url&gt;[^\S]*)).*?&gt;(?&lt;name&gt;.*?)&lt;/a&gt;

Links that aren't quoted (href=blahblah) aren't added to the url group, anybody know what's wrong ???

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.