<a href="http://tieba.baidu.com/f?kw=%B0%AC%B8%A5%C9%AD">艾弗森 </a>
<a href=http://tieba.baidu.com/f?kw=%B0%AC%B8%A5%C9%AD>艾弗森 </a>
<a clas="id" href="http://tieba.baidu.com/f?kw=%B0%AC%B8%A5%C9%AD">艾弗森</a>
@"<a\s+((?!href)[^<>])*href=""(?<href>[^""]+)""[^<>]*>(?<title>[^<>]*)"
@"<a\s+((?!href)[^<>])*href=['""]?(?<href>[^""'<>\s]+)['""]?[^<>]*>(?<title>[^<>]*)"
以上3种A标签形式。要怎么修改以上2个正则表达式才能通过
Groups["href"]和Groups["title"]
获取到http://tieba.baidu.com/f?kw=%B0%AC%B8%A5%C9%AD 和 艾弗森
<a href=http://tieba.baidu.com/f?kw=%B0%AC%B8%A5%C9%AD>艾弗森 </a>
<a clas="id" href="http://tieba.baidu.com/f?kw=%B0%AC%B8%A5%C9%AD">艾弗森</a>
@"<a\s+((?!href)[^<>])*href=""(?<href>[^""]+)""[^<>]*>(?<title>[^<>]*)"
@"<a\s+((?!href)[^<>])*href=['""]?(?<href>[^""'<>\s]+)['""]?[^<>]*>(?<title>[^<>]*)"
以上3种A标签形式。要怎么修改以上2个正则表达式才能通过
Groups["href"]和Groups["title"]
获取到http://tieba.baidu.com/f?kw=%B0%AC%B8%A5%C9%AD 和 艾弗森
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
string[] input = new string[]{@"<a href=""http://tieba.baidu.com/f?kw=%B0%AC%B8%A5%C9%AD"">艾弗森 </a>",
@"<a href=http://tieba.baidu.com/f?kw=%B0%AC%B8%A5%C9%AD>艾弗森 </a> ",
@"<a clas=""id"" href=""http://tieba.baidu.com/f?kw=%B0%AC%B8%A5%C9%AD"">艾弗森 </a> "};
Regex re = new Regex(@"<a\s+((?!href)[^<>])*href=['""]?(?<href>[^""'<>\s]+)['""]?[^ >]*>(?<title>[^<>]*)");
foreach(string s in input)
{
Console.WriteLine("{0} {1}",re.Match(s).Groups["href"].Value,re.Match(s).Groups["title"].Value);
}
}
}
}
http://tieba.baidu.com/f?kw=%B0%AC%B8%A5%C9%AD 艾弗森
http://tieba.baidu.com/f?kw=%B0%AC%B8%A5%C9%AD 艾弗森
http://tieba.baidu.com/f?kw=%B0%AC%B8%A5%C9%AD 艾弗森
Press any key to continue . . .
<a[\s|\S]*?(?:href=[\"\'])(?<href>[^\"\']*)[^>]*>(?<title>[\s|\S]*?(?=</a>))</a>
MatchCollection mc = reg.Matches(str);
foreach (Match m in mc)
{
Console.WriteLine(m.Groups["url"].ToString()+" "+m.Groups["name"].ToString()); }
(?si)是什么意思?
(?i)是什么意思!
以上的这些就一条也读不出来呢?
高手再帮忙看看
MatchCollection mc = reg.Matches(yourStr);
foreach (Match m in mc)
{
richTextBox2.Text += m.Groups["href"].Value + "\n";
richTextBox2.Text += m.Groups["title"].Value + "\n";
}