两个问题
我获取一个页面
1,我想得到从<--title-->,截至到<--/title/-->之间得内容
2,我想把<dd>.........</dd>之间得值获取出来,并且这样的有多个

解决方案 »

  1.   

    1\ string sourceString = @"<--title-->,截至到<--/title/-->";
    string pattern = @"(?<=<--title-->)([\s\S]+?)(?=<--/title/-->)";
    System.Text.RegularExpressions.Match result = Regex.Match(sourceString,pattern,System.Text.RegularExpressions.RegexOptions.IgnoreCase|System.Text.RegularExpressions.RegexOptions.Multiline); while(result.Success)
    {
       WL("正确:" + result.Value);//输出
       result = result.NextMatch();
    }
      

  2.   

    2、 string sourceString = @"<dd>w你好啊</dd><dd>asdfasdfs</dd>";
    string pattern = @"(?<=<dd>)([\s\S]+?)(?=</dd>)";
    System.Text.RegularExpressions.Match result = Regex.Match(sourceString,pattern,System.Text.RegularExpressions.RegexOptions.IgnoreCase|System.Text.RegularExpressions.RegexOptions.Multiline);

    while(result.Success)
    {
       WL("正确:" + result.Value);//输出
       result = result.NextMatch();
    }
      

  3.   

    1,我想得到从<--title-->,截至到<--/title/-->之间得内容如果包含有引号呢?
    比如<--"title"-->
      

  4.   

    1、
    string yourStr = ..............;
    Match m = Regex.Match(yourStr, @"<--title-->([\s\S]*?)<--/title/-->", RegexOptions.IgnoreCase);
    if (m.Success)
    {
        MessageBox.Show(m.Groups[1].Value);
    }2、
    string yourStr = ..............;
    MatchCollection mc = Regex.Matches(yourStr, @"<dd>([\s\S]*?)</dd>", RegexOptions.IgnoreCase);
    foreach (Match m in mc)
    {
        richTextBox2.Text += m.Groups[1].Value + "\n";
    }包含引号那就加上引号就行了
    string yourStr = ..............;
    Match m = Regex.Match(yourStr, @"<--""title""-->([\s\S]*?)<--/title/-->", RegexOptions.IgnoreCase);
    if (m.Success)
    {
        MessageBox.Show(m.Groups[1].Value);
    }
    To:bdbox
    你写的也可以,只是这里Multiline参数没有意义,可以不加,有些参数不需要加的时候最好不要加,比如Compiled参数有时候加了反而会适得其反