本帖最后由 wy811007 于 2012-06-21 15:50:55 编辑

解决方案 »

  1.   


                StreamReader reader = new StreamReader("c:\\1.txt");
                string source = reader.ReadToEnd();
                Regex reg = new Regex(@"(?is)(?<num>\d+).shtml[^>]*title=""(?<title>[^>]*)""");
                MatchCollection mc = reg.Matches(source);
                string[] ss = new string[mc.Count];
                for (int i = 0; i < ss.Length; i++)
                {
                    ss[i] = mc[i].Groups["num"].Value + ":" + mc[i].Groups["title"].Value;
                }
      

  2.   

    用Dictionary<string, string>不错 string input = @"<a href=""/xxx/76166.shtml"" target=""_blank"" title=""xx6"">
    <a href=""/xxx/76165.shtml"" target=""_blank"" title=""xx5"">
    <a href=""/xxx/76164.shtml"" target=""_blank"" title=""xx4"">
    <a href=""/xxx/76163.shtml"" target=""_blank"" title=""xx3"">
    "; 
    Dictionary<string, string> dic = new Dictionary<string, string>();
                foreach (Match m in Regex.Matches(input, @"(?is)<a\b[^>]*?href=([""'\s]?)/xxx/(\d+)\.shtml\1[^>]*?title=([""'\s]?)([^""']*?)\3[^>]*?>"))
                {
                    dic.Add(m.Groups[2].Value, m.Groups[4].Value);
                }            foreach (var m in dic)
                {
                    Console.WriteLine(m.Key + "\t" + m.Value);
                }
      

  3.   

    string s = @"<a href=""/xxx/76166.shtml"" target=""_blank"" title=""xx6"">
    <a href=""/xxx/76165.shtml"" target=""_blank"" title=""xx5"">
    <a href=""/xxx/76164.shtml"" target=""_blank"" title=""xx4"">
    <a href=""/xxx/76163.shtml"" target=""_blank"" title=""xx3"">";
    MatchCollection matches = Regex.Matches(s, @"(?is)<a href=""(.*?)"".+?title=""(.*?)"">");
    foreach (Match match in matches)
    Console.WriteLine(match.Groups[1].Value + "\t" + match.Groups[2].Value);
      

  4.   

    都是高手 谢谢了 不过这个匹配后有重复的咋弄额 我用的 bdmh 大大的