非贪婪C++正则表达式的故障
我想解析以下Lua代码:非贪婪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
[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)
强制性:强制性: