Regular expression, split string by capital letter but ignore TLA
.net, regex
Solution
((?<=[a-z])[A-Z]|[A-Z](?=[a-z]))
or its Unicode-aware cousin
((?<=\p{Ll})\p{Lu}|\p{Lu}(?=\p{Ll}))
when replaced globally with
" $1"
handles
TodayILiveInTheUSAWithSimon
USAToday
IAmSOOOBored
yielding
Today I Live In The USA With Simon
USA Today
I Am SOOO Bored
In a second step you'd have to trim the string.
Problem
I'm using the regex ``` System.Text.RegularExpressions.Regex.Replace(stringToSplit, "([A-Z])", " $1").Trim() ``` to split strings by capital letter, for example: 'MyNameIsSimon' becomes 'My Name Is Simon' I find this incredibly useful when working with enumerations. What I would like to do is change it slightly so that strings are only split if the next letter is a lowercase letter, for example: 'USAToday' would become 'USA Today' Can this be done? EDIT: Thanks to all for responding. I may not have entirely thought this through, in some cases 'A' and 'I' would need to be ignored but this is not possible (at least not in a meaningful way). In my case though the answers below do what I need. Thanks!