由于小弟没学过正则表达式,时间紧迫,要学也得花时间了,所以先请了解的朋友们给点帮助,顺便介绍点关于正则表达式的学习方法!如下:
  <!news name="title" id="title" style="class1"><!/news>就是要从字符串中捕获至少满足此格式<!news name="title"><!/news>的字符串,并且获取其属性值!谢谢大家了!

解决方案 »

  1.   

    http://community.csdn.net/Expert/topic/3337/3337412.xml?temp=2.344912E-02里面找
      

  2.   

    try
    using System;
    using System.Text.RegularExpressions;class TestReg2
    {
     static void Main()
     {
    string s = "  <!news name=\"title\" id=\"title\" style=\"class1\">xxxx<!/news> ";
    Regex re = new Regex(@"<!news(\s*(?<name>[^>=]+)=""(?<value>[^""]*)"")*\s*>(?<content>[^>]*)<!/news>", RegexOptions.IgnoreCase);
    Match m = re.Match(s);
    if (m.Success)
    {
    Console.WriteLine(m.Groups["content"].Value);
    for (int i=0; i <  m.Groups["name"].Captures.Count; i++)
    Console.WriteLine("{0}:{1}={2}",i+1, m.Groups["name"].Captures[i].Value , m.Groups["value"].Captures[i].Value );
    }
     }
      

  3.   

    string s = "  <!news yy=xx tt='xx' name=\"title\" id=\"title\" style=\"class1\" zz=gg >xxxx<!/news> ";
    Regex re = new Regex(@"<!news(\s*(?<name>[^>=]+)=(?:""(?<value>[^""]*)""|'(?<value>[^']*)'|(?<value>[^\s>]*)))*\s*>(?<content>[^>]*)<!/news>", RegexOptions.IgnoreCase);
      

  4.   

    最后问一下,望见谅,我如果替换掉括号中间的任意字符"xxxx"呢?马上结贴  呵呵
      

  5.   

    string s = ".........";
    s = Regex.Replace(s,@"(?<=>)[^>]*(?=<)","new string here");
    Console.WriteLine(s);