组的后续捕获包括逗号或右括号。
regex:
(?<name1>??$.*)s((?<type1>w+)s(?<conv>w+)s(?<name2>w+:?:?)+<(?<type2>[ws]+)>((?<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
问题:
如何不捕获这些逗号和右括号?
你可以试试这个regex:
(?<name1>?{0,2}$.*)s((?<type1>w+)s(?<conv>w+)s(?<name2>w+:{0,2})+<(?<type2>[ws]+)>((?: *(?<args>[^,)]+)[,)])+
更新的RegEx Demo
注意最后一个重复捕获组:
(?: *(?<args>[^,)]+)[,)])+
匹配1+个非逗号、非)
字符,后面必须跟,
或)
。
或者如果我们想让这个正则表达式更严格,那么使用:
(?<name1>?{0,2}$.*)s((?<type1>w+)s(?<conv>w+)s(?<name2>w+:{0,2})+<(?<type2>[ws]+)>( *(?<args>[^,)]+)(?:, *(?<args>[^,)]+))*)
这里最后一个子模式是:
( *(?<args>[^,)]+)(?:, *(?<args>[^,)]+))*)
RegEx Demo 2