'regex "split by commas Saving an inner comma"

I am building a report of active directory distribution groups and i want to get the ManageBy returned as Aviles Gutierrez, Abraham instead of the whole DN

CN=Aviles Gutierrez\, Abraham,OU=Users,OU=TremecTJ,OU=Mexico,DC=Tremec,DC=local

Im trying to create a custom attribute extracting the Managedby with the following regex: '^CN=|\\,,.*'. As result i only get Aviles Gutierrez

How can my regex skip that internal comma after the backslash \, and get 'Aviles Gutierrez, Abraham'



Solution 1:[1]

You can not really "skip" a comma in a single match. But you can capture the part with a capture group using:

^CN=(.*?)(?:,[A-Z]+=|$)

Regex demo

That will capture Aviles Gutierrez\, Abraham and then you can replace the \, with , if you want.

For a match only, and if lookarounds are supported:

(?<=^CN=).*?(?=,[A-Z]+=|$)

Regex demo

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 The fourth bird