Thursday, September 28, 2017

Regex and CN to extract name and first OU



need to extract parts of a CN using regex, had to do a quick output, but not happy with the hard coding like "CN="

CN:
CN=LAW\\, JUDE,OU=VIDEO,OU=External,OU=Security - Administrator Accounts,DC=cool,DC=kats

REGEX:
CN=(?<lastname>\w+)\\\\, (?<firstname>\w+),OU=(?<ou>\w+)

RESULT:

Full match1-24`CN=LAW\\, JUDE,OU=VIDEO`
Group `lastname`4-7`LAW`
Group `firstname`11-15`JUDE`
Group `ou`19-24`VIDEO`