Regex rx = new Regex(@"(?<!\\\\),");
String test = "OU=James\\, Brown,OU=Test,DC=Internal,DC=Net";
This works perfectly, but I want to understand it. I’ve been gooling without success. Can somebody give me a word or phrase that I can use to look this up and understand it.
I would have thought that it should be written like this:
new Regex(@"(\\\\)?,");
I’ve seen the (?zzzzzz) syntax before. It’s the <! part that I’m stumped by.
(?<!…)is a negative look-behind assertion. In your regexthe
,matches a comma obviously. The\\\\matches 2 backslashes. Then(?<!\\\\),matches any commas not preceeded by 2 backslashes.Therefore it will match the
,before the OU and DC, but not between James and Brown: