I have a text (string) that I want in all upper case, except the following:
- Words starting with : (colon)
- Words or strings surrounded by double quotation marks, “”
- Words or strings surrounded by single quotation marks, ”
Everything else should be replaced with its upper case counterpart, and formatting (whitespaces, line breaks, etc.) should remain.
How would I go about doing this using Regex (C# style/syntax)?
I think you are looking for something like this:
:\w+– match words with a colon."[^"]*"|'[^']*'– match quoted text. For escaped quotes, you may use:(.)– capture anything else (you can also try([^"':]*|.), it might be faster).Next, we use a callback for Regex.Replace to do two things:
Working example: http://ideone.com/ORFU8