somdafofadfaofjdoafjdsoafjfafodafjo
ID = "abcd"
Name = "acvngjfodajfodajfoafjdoa"
Title = "sssssssssss"这样的一段内容,如何用正则表达式来获取其中的ID(abcd)?获取到后如何输出到程序中?

解决方案 »

  1.   

    Regex reg=new Regex(@"(?<=ID\s*=\s*"").*?(?="")",RegexOptions.Singleline);
    reg.Ismatch(input).Value;
      

  2.   

    下面的匹配ID只为字母和数字string s = "ID\s?=\s?\"([a-zA-Z0-9]*)\"";
    string s1 = "qweqeq ID=\"qweqwe\" asda=\"sadasd\" asda"RegEx reg = new RrgEx(s);
    Match mat = reg.Match(s1);
    MessageBox.show(mat.result($1));
      

  3.   

    string regexStr = "ID\s*=\s*\"(?<id>[^\"]*)\"";MatchCollection mc = Regex.Matches(yourStr, regexStr);
    foreach(Match m in mc)
    {
        m.Groups["id"].Values;//abcd
    }
      

  4.   

    没明白你的意思,怎么又到group了,主要是Regex和Match类,System.Text.RegularExpressions
    命名空间
      

  5.   

    mobydick(敌伯威|我排著队拿著爱的号码牌) ( ) :
    你的正则表达式不能通过编译的~~~~
      

  6.   

    那就这样
    string regexStr = @"ID\s*=\s*""(?<id>[^""]*)""";