<a href="1.html" style="font-weight: bold;color: #8F2A90">标题1</a>
<a href="2.html">标题2</a>
<a href="3.html">标题3</a>
<a href="4.html">标题4</a>
... ...
现在我想获取 标题2,3,4.... 的 url连接,请问正则表达式要如何填写?
<a href="2.html">标题2</a>
<a href="3.html">标题3</a>
<a href="4.html">标题4</a>
... ...
现在我想获取 标题2,3,4.... 的 url连接,请问正则表达式要如何填写?
void Main()
{
string html=@"<a href=""1.html"" style=""font-weight: bold;color: #8F2A90"">标题1</a>
<a href=""2.html"">标题2</a>
<a href=""3.html"">标题3</a>
<a href=""4.html"">标题4</a>"; foreach(Match m in Regex.Matches(html,@"(?is)<a[^<]*href=(['""])?[2,3,4]\.html\1[^>]*>[^<]*</a>"))
{
Console.WriteLine(m.Value);
}
}/*
<a href="2.html">标题2</a>
<a href="3.html">标题3</a>
<a href="4.html">标题4</a>
*/
这个可能能够满足你的需求了! 初学者路过!
string input =@"<a href=""1.html"" style=""font-weight: bold;color: #8F2A90"">标题1</a>";
string pattern = @"(^<a\s?)([href=]*)(\S[\d.\w]\S*)";
Console.WriteLine("html: {0}", Regex.Match(input, pattern).Groups[3].Value);