正则表达式:从定位标记中查找网址 [英] regular expression: Find url from anchor tag

查看:95
本文介绍了正则表达式:从定位标记中查找网址的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有问题. 我想找出由锚标签中的标题"标签组成的url形式的锚标签.

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

我该如何匹配字符串并使用正则表达式获取url.

谢谢

解决方案

<a\s+([^>]*)href="(https?:\/\/([^"]*))"\s+([^>]*)title="xyz"(.*?)>(.*?)<\/a>您可以通过部分匹配$2获取网址,也可以尝试

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

解决方案

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

这篇关于正则表达式:从定位标记中查找网址的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆