tags:

views:

64

answers:

3

hi to all,

i have problem . i want to find out the url form acnchor tag which consist "title" tag in anchor tag.

example:
<a href="http://www.test.com" title="xyz">this is test</a>

how can i match the string and fetch url using regular expression.

thanks

+1  A: 

To be honest, I would use an HTML parsing library to just get the contents of the href attribute.

Daniel Egeberg
A: 

/href="(.*)(?=".*title)/

you will have to trim the href=" from the beginning of the match

/abc(?=xyz)/ positive lookahead -> matches abc if abc is followed by xyz

Biroka
+2  A: 

<a\s+([^>]*)href="(https?:\/\/([^"]*))"\s+([^>]*)title="xyz"(.*?)>(.*?)<\/a> you can get the url by partial match $2, you can try it here

Note that attribute values can contain plain `>` characters.
Gumbo
true, but thats good right? because it wont stop matching urls until it hits a " because of this `[^"]*`