求助大侠一段源代码中,很多类似
<a href="read-htm-tid-4546.html" id="a_ajax_4546">今后转移工作重点</a>
<a href="read-htm-tid-7969541.html" id="a_ajax_7969541">检讨书一份</a>
这样的。我需要提取 一个帖子号码 和 一个标题,如下:
4546 和 今后转移工作重点
7969541 和 检讨书一份要求每个数组里存帖子号码,和标题,中间用逗号分开,求正则表达式!我用的如下代码
MatchCollection mc = Regex.Matches(strHtmlBody, 这里怎么写);
            string[] result = new string[mc.Count];
            for (int i = 0; i < mc.Count; i++)
            {
                result[i] = mc[i].Value;
            }

解决方案 »

  1.   

    本帖最后由 caozhy 于 2012-10-06 19:26:53 编辑
      

  2.   

    id 4546 text 今后转移工作重点
    id 7969541 text 检讨书一份
    Press any key to continue . . .
      

  3.   

    try...MatchCollection mc = Regex.Matches(yourStr, @"(?is)<a href=""read-htm-tid-(?<number>[^.]+)\.html""[^>]*>(?<title>.*?)</a>");
    string[] result = new string[mc.Count];
    for (int i = 0; i < mc.Count; i++)
    {
       result[i] = mc[i].Groups["number"].Value + "," + mc[i].Groups["title"].Value;
    }
    //测试代码
    foreach (string s in result)
    {
       richTextBox2.Text += s + "\n";
    }
    /*-----输出-----
    4546,今后转移工作重点
    7969541,检讨书一份
    */