regular expression: Find url from anchor tag
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开发者_如何学Python match the string and fetch url using regular expression.
thanks
<a\s+([^>]*)href="(https?:\/\/([^"]*))"\s+([^>]*)title="xyz"(.*?)>(.*?)<\/a>
you can get the url by partial match $2
, you can try it here
To be honest, I would use an HTML parsing library to just get the contents of the href
attribute.
/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
精彩评论