<title>aaaaa</title>
想提取出aaaaa 里面这个aaaaa长度不固定 内容不固定 也就是.*

解决方案 »

  1.   

    能把
    <title>aaaaa</title>
    取出来
      

  2.   

    <title id="ti" return="server">aaaaa</title>
    string str=ti.InnerText;
    int i=str.Lengthi就是字符串的长度
      

  3.   


    (?<=<title>).*(?=</title)
      

  4.   

    "(?si)<title>(?<title>.*?)</title>"
    捕获组 title 即为所求。
      

  5.   

                string pa = @"(?<=<title>).*(?=</title)";
                Regex reg = new Regex(pa);
                Match m = reg.Match("<title>aaaaa</title>");
                string s=m.Value;
      

  6.   

    表4.常用分组语法
    分类 代码/语法 说明
    捕获 (exp) 匹配exp,并捕获文本到自动命名的组里
    (?<name>exp) 匹配exp,并捕获文本到名称为name的组里,也可以写成(?'name'exp)
    (?:exp) 匹配exp,不捕获匹配的文本,也不给此分组分配组号
    零宽断言 (?=exp) 匹配exp前面的位置
    (?<=exp) 匹配exp后面的位置
    (?!exp) 匹配后面跟的不是exp的位置
    (?<!exp) 匹配前面不是exp的位置
    注释 (?#comment) 这种类型的分组不对正则表达式的处理产生任何影响,用于提供注释让人阅读
      

  7.   

    把空格去掉,空格是csdn给我加的
      

  8.   


                string pa = @"(?<=<title>).*(?=</title)";
                Regex reg = new Regex(pa);
                Match m = reg.Match("<title>aaaaa</title>");
                string s=m.Value;
      

  9.   

    angel6709,能把你前面发的那个正则的文档给我一份吗 [email protected],先谢谢了
      

  10.   


    string input = @"<title>aaa
    aaa</title>";
    string pattern1 = "(?is)(?<=<title>)((?!</title>).)*";
    string pattern2 = "(?is)(?<=<title>).*?(?=</title>)";
    Match m = Regex.Match(input, pattern1);
    while(m.Success)
    {
        Console.WriteLine(m.Value);
        m = m.NextMatch();
    }
    MatchCollection mc = Regex.Matches(input, pattern2);
    foreach(Match m in mc)
    {
        Console.WriteLine(m.Value);
    }