正则表达式一直都不是很擅长,时间长了还忘了不少,请问下面的字符串怎么解析出Variables,T,Time,F后面的变量:
Variables = "x1","x2","v1","v2","type" ZONE T=" Time =  1.8000E-05 " F=FEPOINT
我写的是:@"^\s*Variables\s*=\s*(?<id1>)\s*ZONE\s*T=\s*(?<id2>)\s*F=\s*(?<id3>)\s*"
通过id1,id2,id3获取对应的值,
"x1","x2","v1","v2" 
" Time =  1.8000E-05 "
FEPOINT
但是结果却是空的,请问哪个部分错了呢?正则表达式

解决方案 »

  1.   

    (?is)Variables\s*=\s*(?<id1>.*?)\s*ZONE\s*T\s*=\s*(?<id2>.*?)\s*F\s*=\s*(?<id3>.*?)(?=$)
      

  2.   

      string pattern = @"(?i)\s*Variables\s*=\s*(?<id1>[^\s]*?)\s*,['""]type['""]\s*?ZONE\s*T=\s*(?<id2>[\s\S]*?)\s*?F=\s*?(?<id3>[\s\S]*?)(?=\s|$)";
      

  3.   

    只能读出id1啊,也就是只能得到"x1","x2","v1","v2" ,剩下的两个没法得到
      

  4.   

    这个得到的结果是"x1","x2","v1","v2"后面两个变量id2,id3没有结果
      

  5.   

    没、懂,给个完整的代码  string sourcestr = @"Variables = ""x1"",""x2"",""v1"",""v2"",""type"" ZONE T="" Time =  1.8000E-05 "" F=FEPOINT";
                Regex regstr = new Regex(@"(?is)Variables\s*=\s*(?<id1>.*?)\s*ZONE\s*T\s*=\s*(?<id2>.*?)\s*F\s*=\s*(?<id3>.*?)(?=$)");
                Console.WriteLine(regstr.Match(sourcestr).Groups["id1"].Value);
                Console.WriteLine(regstr.Match(sourcestr).Groups["id2"].Value);
                Console.WriteLine(regstr.Match(sourcestr).Groups["id3"].Value);
      

  6.   


     string sourcestr = @"Variables = ""x1"",""x2"",""v1"",""v2"",""type"" ZONE T="" Time =  1.8000E-05 "" F=FEPOINT";
                Regex regstr = new Regex(@"(?i)Variables\s*=\s*(?<id1>.*?)\s*,\s*""type""\s*ZONE\s*T\s*=\s*(?<id2>.*?)\s*F\s*=\s*(?<id3>.*?)(?=$)");
                Console.WriteLine(regstr.Match(sourcestr).Groups["id1"].Value);
                Console.WriteLine(regstr.Match(sourcestr).Groups["id2"].Value);
                Console.WriteLine(regstr.Match(sourcestr).Groups["id3"].Value);