@"<a[^>]*?href=([""']?)(?<url>[^""'\s>]*)\1[^>]*>"
匹配超链接。这个是你之前给我的。。但现在有遇到几种情况,一个就是连接是单引号的。如<a href ='newsdetails.aspx?news_id=81804' class="general">就没办法抓下来了,还有就是换行和空格。
没办法,再次求助于你。。
匹配超链接。这个是你之前给我的。。但现在有遇到几种情况,一个就是连接是单引号的。如<a href ='newsdetails.aspx?news_id=81804' class="general">就没办法抓下来了,还有就是换行和空格。
没办法,再次求助于你。。
MatchCollection mc = reg.Matches(yourStr);
foreach (Match m in mc)
{
richTextBox2.Text += m.Groups["url"].Value + "\n";
}如果还有不满足的,比如你说的换行和空格,给出实例
<td width="1%"> </td>
<td colspan="2">
<a href ='newsdetails.aspx?news_id=81804' class="general">
<font color="#1C4E8D" face="arial" style="font-size:15px"><b> Retail chain Buslik is expanding across the country
</b></font></a>
<br>
<font color="#1C4E8D" face="arial" style="font-size:11px">
January 30, 2010
</font> <font font color="#1C4E8D" face="arial" style="font-size:11px">(Belarus)</font>
</td>
<td width="1%"> </td> </tr>
主要是一些外国的网站。谢谢啊。我先试试。
http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?这是DZNT的方法
readonly static Regex RgValidURL = new Regex(@"^(http|https)\://([a-zA-Z0-9\.\-]+(\:[a-zA-Z0-9\.&%\$\-]+)*@)*((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|localhost|([a-zA-Z0-9\-]+\.)*[a-zA-Z0-9\-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{1,10}))(\:[0-9]+)*(/($|[a-zA-Z0-9\.\,\?\'\\\+&%\$#\=~_\-]+))*$", RegexOptions.Compiled);
http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?这是DZNT的方法
readonly static Regex RgValidURL = new Regex(@"^(http|https)\://([a-zA-Z0-9\.\-]+(\:[a-zA-Z0-9\.&%\$\-]+)*@)*((25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9])\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[1-9]|0)\.(25[0-5]|2[0-4][0-9]|[0-1]{1}[0-9]{2}|[1-9]{1}[0-9]{1}|[0-9])|localhost|([a-zA-Z0-9\-]+\.)*[a-zA-Z0-9\-]+\.(com|edu|gov|int|mil|net|org|biz|arpa|info|name|pro|aero|coop|museum|[a-zA-Z]{1,10}))(\:[0-9]+)*(/($|[a-zA-Z0-9\.\,\?\'\\\+&%\$#\=~_\-]+))*$", RegexOptions.Compiled); 两个都是对的