Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 用匹配括号挑战正则表达式_C#_Regex_Parsing - Fatal编程技术网

C# 用匹配括号挑战正则表达式

C# 用匹配括号挑战正则表达式,c#,regex,parsing,C#,Regex,Parsing,我花了太多时间试图提取这个。我有下面的消息,我想在参数之前提取消息“data{{{…}}”的数据部分。我不能依赖于消息的顺序,因此可以在消息中以任何顺序看到参数结果和命令 invokeid 3 data {{GainID|Value(dB)} {0|0} {1|18} {2|17} {3|-1} {4|-255} {5|0} {6|12} {7|11} {8|10} {9|9} {10|8} {11|7} {12|6} {13|5} {14|4} {15|3} {16|2} {17|1} {

我花了太多时间试图提取这个。我有下面的消息,我想在参数之前提取消息“data{{{…}}”的数据部分。我不能依赖于消息的顺序,因此可以在消息中以任何顺序看到参数结果和命令

invokeid 3  data {{GainID|Value(dB)}  {0|0} {1|18} {2|17} {3|-1} {4|-255} {5|0} {6|12} {7|11} {8|10} {9|9} {10|8} {11|7} {12|6} {13|5} {14|4} {15|3} {16|2} {17|1} {18|0} {19|-1} {20|-2} {21|-3} {22|-4} {23|-5} {24|-6} {25|-7} {26|-8} {27|-9} {28|-10} {29|-11} {30|-12} {31|-13} {32|-14} {33|-15} {34|-16} {35|-17} {36|-18} {37|-19} {38|-20} {39|-21} {40|-22} {41|-23} {42|-24} {43|-25} {44|-26} {45|-27} {46|-28} {47|0}} arguments {{ DisplayGain -1 }} result 0 command OAMPCMD IPaddress 0.0.0.0
这是我想要解析的

data {{GainID|Value(dB)}  {0|0} {1|18} {2|17} {3|-1} {4|-255} {5|0} {6|12} {7|11} {8|10} {9|9} {10|8} {11|7} {12|6} {13|5} {14|4} {15|3} {16|2} {17|1} {18|0} {19|-1} {20|-2} {21|-3} {22|-4} {23|-5} {24|-6} {25|-7} {26|-8} {27|-9} {28|-10} {29|-11} {30|-12} {31|-13} {32|-14} {33|-15} {34|-16} {35|-17} {36|-18} {37|-19} {38|-20} {39|-21} {40|-22} {41|-23} {42|-24} {43|-25} {44|-26} {45|-27} {46|-28} {47|0}} 
它是通过以下代码完成的:

        string ret = String.Empty;
        Regex regEx = new Regex("data {{.*}}");
        Match regExMatch = regEx.Match(iqMessage);
        if (!regExMatch.Success)
            throw new IqScriptControlMessageParseException(String.Format("Could not find {0}.", DATA));

        ret = regExMatch.Value.Substring(DATA.Length).Trim();
我无法成功地构建一个有效的正则表达式。如果您能提供帮助,我们将不胜感激。如果你知道我的意思,我将手动编写提取代码

感谢使用非贪婪匹配(
*?
而不是
*
),并避开卷发(它们在正则表达式中有特殊含义):


根据数据的不同,这仍然可能与您所追求的目标不匹配。查看平衡组以解决该问题。(见:)
Regex regEx = new Regex(@"data \{\{.*?\}\}");