开发者

regular expression: Find url from anchor tag

开发者 https://www.devze.com 2023-01-09 17:49 出处:网络
i have problem . i want to find out the url form acnchor tag which consist \"title\" tag in 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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号