RegEx assistance for adding a space before an Upper case letter
-
I have hundreds of table column names that contain no embedded spaces. Some of the column names use an _ to separate words, some use camel case, some use a mixture. Replacing the _ with a space is easy. But how to add a space prior to any upper case character that is not the first character and is not already preceded by a space? Each column name will be on a separate line. Thanks for any help
Example:
Average_Balance
SystemRate_Change
DateClosedDesired Results:
Average Balance
System Rate Change
Date Closed -
Hello, @brenda-gross-0 and All,
Very easy with regexes !
-
Open the Replace dialog (
Ctrl + H) -
Un-tick all box options
-
FIND
(?-i)(?<=\l)(?=\u)|_ -
REPLACE
\x20 -
Tick the
Wrap aroundoption -
Select the
Regular expressionsearch mode -
Click, once only, on the
Replace Allbutton
Voila !
Notes :
-
The leading part
(?-i)is an in-line modifier which force to take care about the case of letters, meaning non-insensitive search ! -
Then, due to the alternation symbol
|, two individual regexes are performed, simultaneously :-
(?<=\l)(?=\u)which searches for an empty string between a lower-case letter and an upper-case letter -
_which simply searches for the underline character
-
-
In both cases, the replacement changes the regex search with an normal space character
\x20. I could have chosen to type a single space char, instead ! -
The regex search may also be expressed as a non-capturing group :
(?-i:(?<=\l)(?=\u)|_), with the leading non-insensitive option
Best Regards,
guy038
-