<span class="th_replyer j_replyer" title="最后回复人"><a href="/i/sys/jump?un=taobao0327" target="_blank">taobao0327</a></span>
<span class="th_replyer j_replyer" title="最后回复人">124.236.32.*</span><span class="th_author" title="主题作者" ><a href="/i/sys/jump?un=taobao0327" target="_blank">taobao0327</a></span>
<span class="th_author" title="主题作者" >120.14.38.*</span>
获取源码中这样文本格式中的回复人和主题作者的用户名
我写的.
(?<=<span class="(th_replyer j_replyer|th_author)" title="(最后回复人|主题作者)">(<a .*>){0,1}).+?(?=</)
可获取会带上<a href.... 字符串 实在想不出来怎么写 了.

解决方案 »

  1.   


                StreamReader reader = new StreamReader("e:\\1.txt",Encoding.Default);
                string content = reader.ReadToEnd();
                Regex reg = new Regex(@"(?is)(?<=<span class=""(th_replyer j_replyer|th_author)"" title=""(最后回复人|主题作者)"">(<a href[^>].*>){0,1})[^<>""]+?(?=</)");
                MatchCollection ms = reg.Matches(content);
                foreach (Match m in ms)
                {
                    MessageBox.Show(m.Value);
                }
      

  2.   


       string tempStr = File.ReadAllText(@"C:\Users\M\Desktop\Test.txt", Encoding.GetEncoding("GB2312"));
                string pattern = @"(?<=<span[^>]*?class=(['""]?)(th_replyer|th_author)[^>]*?>)\s*?(?<Link><a[^>]*?>(?<UserName>[\s\S]*?)</a>)\s*?(?=</span>)";        
                foreach (Match m in Regex.Matches(tempStr, pattern))
                {
                    string result = m.Value;//循环输出
                    string Link = m.Groups["Link"].Value;//<a href="/i/sys/jump?un=taobao0327" target="_blank">taobao0327</a>
                    string UserName = m.Groups["UserName"].Value;//taobao0327            }
      

  3.   

    你用源码测试下.....
    http://tieba.baidu.com/f?kw=%E3%FE%CE%E2%B4%E5
      

  4.   

    string input = File.ReadAllText(@"C:\Test.txt", Encoding.GetEncoding("GB2312"));
                string pattern = @"(?is)<span\b[^>]*?class=""(th_replyer j_replyer|th_author)""[^>]*?title=""(最后回复人|主题作者)""[^>]*?>(<a\b[^>]*?>)?(.*?)(</a>)?</span>";        
                foreach (Match m in Regex.Matches(input , pattern))
                {
                    string result = m.Value;//链接
                    string UserName = m.Groups[4].Value;//回复人和主题作者的用户名都在            }
      

  5.   

    <span\b(?>(?:(?!\btitle\b|[<>]).)*)*title\s*=\s*(?<ko>["']*)(?:\s*(?:最后回复人|主题作者)\s*)\k<ko>(?>[^><]*)>\s*<a\b(?>[^><]*)>(?<Name>[^><]+)