Tohuw
Tohuw

Reputation: 3800

How Can I Regex Match The Common Name of This DN?

Given the string CN=Smith\, John,OU=Users,OU=IT,DC=contoso,DC=com, I am seeking to match the complete common name, including the comma after it. I'm really trying to remove this part, so matching the other part would work too.

The result after removal or filter ought to be OU=Users,OU=IT,DC=contoso,DC=com.

I tried ^.+(?=,OU=) with no flags but this captures CN=Some\, Guy,OU=Users

The language/regex standard is PowerShell, but I can figure out the conversion from another standard, so any solution is likely better than where I am.

Upvotes: 1

Views: 766

Answers (1)

Ibrahim Najjar
Ibrahim Najjar

Reputation: 19423

You can try this: ^.+?(?=,OU=), and it shell match the entire string until the OU part.

Upvotes: 2

Related Questions