Given the expression ^(?<res>a).*(?<res>c) and test string abc, expected named group res to concat both found values and get ac, but got latest change – c.
Any way for C#’s regex class to support concat for named groups within regex?
Related question is Regex issue with named captured pairs, and by the chance it says that Perl/PCRE does not supports duplicate named pairs, but here I got .NET, and looking for it’s specific magic to make regex return a single match that contains both found values from different parts of string (that is, abbbbbcdef should return ac).
Calling regex more than once or joining resulting groups in code is not a well-tolerated solution now – looking to do the whole job inside regex.
Current solution is to assign group names in ascending order for each condition:
((?<group0>))|((?<group1>)(?<group0>))After matching, all found groups are put to list and sorted by their name, building a final query string from either
group0,group1or justgroup0(depending on what condition was matched).Another trick is the need to start matching from beginning:
^(?wastebytes(condition)(chance1)|(chance2))