组的后续捕获包括逗号或右括号。
正则表达式:
(?<name1>\?\?\$.*)\s\((?<type1>\w+)\s(?<conv>\w+)\s(?<name2>\w+:?:?)+<(?<type2>[\w\s]+)>\((?<args>.+?(?=[,)]))+\)
输入:
??$PlotBarGroups@C@ImPlot@@YAXQBQBDPBCHHNNH@Z (void __cdecl ImPlot::PlotBarGroups<signed char>(char const * const * const,signed char const *,int,int,double,double,int))
??$PlotBarGroups@E@ImPlot@@YAXQBQBDPBEHHNNH@Z (void __cdecl ImPlot::PlotBarGroups<unsigned char>(char const * const * const,unsigned char const *,int,int,double,double,int))
??$PlotBarGroups@F@ImPlot@@YAXQBQBDPBFHHNNH@Z (void __cdecl ImPlot::PlotBarGroups<short>(char const * const * const,short const *,int,int,double,double,int))
??$PlotBarGroups@G@ImPlot@@YAXQBQBDPBGHHNNH@Z (void __cdecl ImPlot::PlotBarGroups<unsigned short>(char const * const * const,unsigned short const *,int,int,double,double,int))
??$PlotBarGroups@H@ImPlot@@YAXQBQBDPBHHHNNH@Z (void __cdecl ImPlot::PlotBarGroups<int>(char const * const * const,int const *,int,int,double,double,int))
??$PlotBarGroups@I@ImPlot@@YAXQBQBDPBIHHNNH@Z (void __cdecl ImPlot::PlotBarGroups<unsigned int>(char const * const * const,unsigned int const *,int,int,double,double,int))
??$PlotBarGroups@M@ImPlot@@YAXQBQBDPBMHHNNH@Z (void __cdecl ImPlot::PlotBarGroups<float>(char const * const * const,float const *,int,int,double,double,int))
??$PlotBarGroups@N@ImPlot@@YAXQBQBDPBNHHNNH@Z (void __cdecl ImPlot::PlotBarGroups<double>(char const * const * const,double const *,int,int,double,double,int))
??$PlotBarGroups@_J@ImPlot@@YAXQBQBDPB_JHHNNH@Z (void __cdecl ImPlot::PlotBarGroups<__int64>(char const * const * const,__int64 const *,int,int,double,double,int))
??$PlotBarGroups@_K@ImPlot@@YAXQBQBDPB_KHHNNH@Z (void __cdecl ImPlot::PlotBarGroups<unsigned __int64>(char const * const * const,unsigned __int64 const *,int,int,double,double,int))
实际结果:
signed char
char const * const * const
,signed char const *
,int
,int
,double
,double
,int
)
预期结果:
signed char
char const * const * const
signed char const *
int
int
double
double
int
在线示例:
https://regex101.com/r/Fkyk4P/1
问题:
如何才能不捕获这些逗号和右括号?
最佳答案
您可以尝试这个正则表达式:
(?<name1>\?{0,2}\$.*)\s\((?<type1>\w+)\s(?<conv>\w+)\s(?<name2>\w+:{0,2})+<(?<type2>[\w\s]+)>\((?: *(?<args>[^,)]+)[,)])+
记下最后一个重复捕获组:
(?: *(?<args>[^,)]+)[,)])+
匹配 1 个以上非逗号、非 )
字符,且后面必须跟有 、
或 )
。
或者如果我们想让这个正则表达式更严格,那么使用:
(?<name1>\?{0,2}\$.*)\s\((?<type1>\w+)\s(?<conv>\w+)\s(?<name2>\w+:{0,2})+<(?<type2>[\w\s]+)>\( *(?<args>[^,)]+)(?:, *(?<args>[^,)]+))*\)
最后一个子模式是:
\( *(?<args>[^,)]+)(?:, *(?<args>[^,)]+))*\)
关于正则表达式捕获重复组中不需要的字符,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74650822/