Reputation: 4211
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
Upvotes: 0
Views: 6792
Reputation: 609
/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
Upvotes: 0
Reputation: 5846
<a\s+([^>]*)href="(https?:\/\/([^"]*))"\s+([^>]*)title="xyz"(.*?)>(.*?)<\/a>
you can get the url by partial match $2
, you can try it here
Upvotes: 4
Reputation: 8382
To be honest, I would use an HTML parsing library to just get the contents of the href
attribute.
Upvotes: 2