You can go and look for lowercase letters that are not preceded by an odd number of backslashes:
(?<!(?<!\\)(?:\\\\)*\\)\p{Ll}+
Then pass the match to the MatchEvaluator , write it down and replace the text in the original line. I don't know C #, so this may not work right away (the code snippet is made and slightly modified from RegexBuddy ), but this is the start:
string resultString = null; resultString = Regex.Replace(subjectString, @"(?<! # Negative lookbehind: (?<!\\)(?:\\\\)*\\ # Is there no odd number of backslashes | # nor \(\?<?\p{L}* # (?<tags or (?modifiers ) # before the current position? \p{Ll}+ # Then match one or more letters", new MatchEvaluator(ComputeReplacement), RegexOptions.IgnorePatternWhitespace); public String ComputeReplacement(Match m) { // You can vary the replacement text for each match on-the-fly return @"\0".ToUpper(); // or whatever is needed for uppercasing in .NET }
Explanation:
(?<!
source share