I couldn't get the aix solution to work (and it doesn't work on RegExr either), so I came up with my own, which I tested, and seems to be doing exactly what you are looking for:
((^[az]+)|([AZ]{1}[az]+)|([AZ]+(?=([AZ][az])|($))))
and here is an example of its use:
; Regex Breakdown: This will match against each word in Camel and Pascal case strings, while properly handling acrynoms. ; (^[az]+) Match against any lower-case letters at the start of the string. ; ([AZ]{1}[az]+) Match against Title case words (one upper case followed by lower case letters). ; ([AZ]+(?=([AZ][az])|($))) Match against multiple consecutive upper-case letters, leaving the last upper case letter out the match if it is followed by lower case letters, and including it if it followed by the end of the string. newString := RegExReplace(oldCamelOrPascalString, "((^[az]+)|([AZ]{1}[az]+)|([AZ]+(?=([AZ][az])|($))))", "$1 ") newString := Trim(newString)
Here, I separate each word with a space, so here are a few examples of how the string is converted:
- ThisIsATitleCASEString => This is a CASE header line
- andThisOneIsCamelCASE =>, and this is one of CEMEL Camel
This solution above does what the original message requests, but I also needed a regular expression to search for camel and pascal strings that included numbers, so I also came up with this variation to include numbers:
((^[az]+)|([0-9]+)|([AZ]{1}[az]+)|([AZ]+(?=([AZ][az])|($)|([0-9]))))
and an example of its use:
; Regex Breakdown: This will match against each word in Camel and Pascal case strings, while properly handling acrynoms and including numbers. ; (^[az]+) Match against any lower-case letters at the start of the command. ; ([0-9]+) Match against one or more consecutive numbers (anywhere in the string, including at the start). ; ([AZ]{1}[az]+) Match against Title case words (one upper case followed by lower case letters). ; ([AZ]+(?=([AZ][az])|($)|([0-9]))) Match against multiple consecutive upper-case letters, leaving the last upper case letter out the match if it is followed by lower case letters, and including it if it followed by the end of the string or a number. newString := RegExReplace(oldCamelOrPascalString, "((^[az]+)|([0-9]+)|([AZ]{1}[az]+)|([AZ]+(?=([AZ][az])|($)|([0-9]))))", "$1 ") newString := Trim(newString)
And here are some examples of how a string with numbers is converted using this regular expression:
- myVariable123 => my Variable 123
- my2Variables => my 2 Variables
- The3rdVariableIsHere => 3 rdVariable Is Here
- 12345NumsAtTheStartIncludedToo => 12345 Nums At The Start Included Too
deadlydog Mar 11 '12 at 6:40 2012-03-11 06:40
source share