开发者

How to get two pieces from a link?

开发者 https://www.devze.com 2023-03-03 04:01 出处:网络
The link looks like this <a href=\"http://msdn.microsoft.com/en-us/library/Aa538627.aspx\" onclick=\"trackClick(this, \'117\', \'http\\x3a\\x2f\\x2fmsdn.microsoft.com\\x2fen-us\\x2flibrary\\x2fAa5

The link looks like this

<a href="http://msdn.microsoft.com/en-us/library/Aa538627.aspx" onclick="trackClick(this, '117', 'http\x3a\x2f\x2fmsdn.microsoft.com\x2fen-us\x2flibrary\x2fAa538627.aspx', '15');">To开发者_如何学ColStripItemOwnerCollectionUIAdapter.GetInsertingIndex Method ...</a>

I want to retrieve the link (from href), and get the text in between get this.

Not sure how to do it


/<a[^>]*\s+href\s*=\s*\"([^"]+)"[^>]*>(.*?)</a>/gi

This pattern should match most well-behaved links and provide the URL in group 1 and the text in group 2. For everything more complicated than that use a HTML parser.

0

精彩评论

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

关注公众号