Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/19.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/go/7.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_C++11_Regex Greedy - Fatal编程技术网

非贪婪C++正则表达式的故障

非贪婪C++正则表达式的故障,c++,regex,c++11,regex-greedy,C++,Regex,C++11,Regex Greedy,我想解析以下Lua代码: [1]={['x']=198;['y']=74;['width']=99;['height']=199;};[2]={['x']=82;['y']=116;['width']=82;['height']=164;}; 请注意,表中有两个键:[1]和[2]。我只想获取[1]键的值。我该怎么做?我尝试了以下方法: cmatch res; regex rx("\\[(.*)?\\]=\\{(.*)?\\};(.*)"); regex_search(lua_table.c_s

我想解析以下Lua代码:

[1]={['x']=198;['y']=74;['width']=99;['height']=199;};[2]={['x']=82;['y']=116;['width']=82;['height']=164;};
请注意,表中有两个键:[1]和[2]。我只想获取[1]键的值。我该怎么做?我尝试了以下方法:

cmatch res;
regex rx("\\[(.*)?\\]=\\{(.*)?\\};(.*)");
regex_search(lua_table.c_str(), res, rx);

但它仍然很贪婪:它匹配整个文本。

您通过放置?在他们之外。而是将它们放在组中。*?有关前两个分组的非贪婪匹配,请参阅捕获组2了解匹配结果

\\[(.*?)\\]=\\{(.*?)\\};(.*)

您通过放置以下内容使您的捕获组成为可选组?在他们之外。而是将它们放在组中。*?有关前两个分组的非贪婪匹配,请参阅捕获组2了解匹配结果

\\[(.*?)\\]=\\{(.*?)\\};(.*)

只有在右大括号后面跟有{}个大括号时,才可以使用lookahead和lookahead来匹配{}大括号中的所有字符;任何角色

(?<=\\{)(.*?)(?=\\};.)

只有在右大括号后面跟有{}个大括号时,才可以使用lookahead和lookahead来匹配{}大括号中的所有字符;任何角色

(?<=\\{)(.*?)(?=\\};.)

这与@hwnd相同,只是有一些更详细的信息

 # [1]={['x']=198;['y']=74;['width']=99;['height']=199;};[2]={['x']=82;['y']=116;['width']=82;['height']=164;};  
 #  **  Grp 0 -  ( pos 0 , len 108 ) 
 # [1]={['x']=198;['y']=74;['width']=99;['height']=199;};[2]={['x']=82;['y']=116;['width']=82;['height']=164;};  
 #  **  Grp 1 -  ( pos 1 , len 1 ) 
 # 1  
 #  **  Grp 2 -  ( pos 5 , len 47 ) 
 # ['x']=198;['y']=74;['width']=99;['height']=199;  
 #  **  Grp 3 -  ( pos 54 , len 54 ) 
 # [2]={['x']=82;['y']=116;['width']=82;['height']=164;};  

 # "\\[(.*?)\\]=\\{(.*?)\\};(.*)"

 \[
 ( .*? )                       # (1)
 \]
 =
 \{
 ( .*? )                       # (2)
 \}
 ;
 ( .* )                        # (3)

这与@hwnd相同,只是有一些更详细的信息

 # [1]={['x']=198;['y']=74;['width']=99;['height']=199;};[2]={['x']=82;['y']=116;['width']=82;['height']=164;};  
 #  **  Grp 0 -  ( pos 0 , len 108 ) 
 # [1]={['x']=198;['y']=74;['width']=99;['height']=199;};[2]={['x']=82;['y']=116;['width']=82;['height']=164;};  
 #  **  Grp 1 -  ( pos 1 , len 1 ) 
 # 1  
 #  **  Grp 2 -  ( pos 5 , len 47 ) 
 # ['x']=198;['y']=74;['width']=99;['height']=199;  
 #  **  Grp 3 -  ( pos 54 , len 54 ) 
 # [2]={['x']=82;['y']=116;['width']=82;['height']=164;};  

 # "\\[(.*?)\\]=\\{(.*?)\\};(.*)"

 \[
 ( .*? )                       # (1)
 \]
 =
 \{
 ( .*? )                       # (2)
 \}
 ;
 ( .* )                        # (3)
强制性:强制性: