Regx查找href的值 [英] Regx Find Href value
本文介绍了Regx查找href的值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有,我有锚标记,我想知道这些锚标签的href值的字符串。
我的字符串是这样的:
I have a string in which I have anchor tag I want to know the href values of those anchor tags. my string is like:
This is Test page <a href='test.aspx'>test page</a> .
在此,我想找到的价值HREF即 Test.aspx文件
in this I want to find the value of href i.e. test.aspx
请给我建议任何好的regx组这一点。
Please suggest me any good regx group for this.
推荐答案
如果您使用&LT; A [^&GT;] * HREF =(?:?。(小于HREF&GT; *? )')|(?:?。?(小于HREF&GT; *))
那么结果将被存储在指定的组HREF
if you use <a [^>]*href=(?:'(?<href>.*?)')|(?:"(?<href>.*?)")
then the result will be stored in the named group href
例如:
var inputString="This is Test page <a href='test.aspx'>test page</a>";
var regex=new Regex("<a [^>]*href=(?:'(?<href>.*?)')|(?:\"(?<href>.*?)\")",RegexOptions.IgnoreCase);
var urls=regex.Matches(inputString).OfType<Match>().Select(m =>m.Groups["href"].Value);
URL将包含字符串的HREF的集合。
urls will be a collection of strings containing the hrefs.
这篇关于Regx查找href的值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文