Я не смог заставить работать решение aix (и оно не работает на RegExr), поэтому я нашел свое собственное, которое я протестировал, и, похоже, делает именно то, что вы ищете:
((^[a-z]+)|([A-Z]{1}[a-z]+)|([A-Z]+(?=([A-Z][a-z])|($))))
и вот пример его использования:
; Regex Breakdown: This will match against each word in Camel and Pascal case strings, while properly handling acrynoms.
; (^[a-z]+) Match against any lower-case letters at the start of the string.
; ([A-Z]{1}[a-z]+) Match against Title case words (one upper case followed by lower case letters).
; ([A-Z]+(?=([A-Z][a-z])|($))) 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's followed by the end of the string.
newString := RegExReplace(oldCamelOrPascalString, "((^[a-z]+)|([A-Z]{1}[a-z]+)|([A-Z]+(?=([A-Z][a-z])|($))))", "$1 ")
newString := Trim(newString)
Здесь я разделяю каждое слово пробелом, поэтому вот несколько примеров преобразования строки:
- ThisIsATitleCASEString => Это строка заголовка CASE
- andThisOneIsCamelCASE => и это верблюд CASE
Это решение, описанное выше, делает то, о чем просит оригинальная запись, но мне также понадобилось регулярное выражение для поиска верблюжьих и паскальских строк, которые включали числа, поэтому я также придумал этот вариант, чтобы включить числа:
((^[a-z]+)|([0-9]+)|([A-Z]{1}[a-z]+)|([A-Z]+(?=([A-Z][a-z])|($)|([0-9]))))
и пример использования:
; Regex Breakdown: This will match against each word in Camel and Pascal case strings, while properly handling acrynoms and including numbers.
; (^[a-z]+) 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).
; ([A-Z]{1}[a-z]+) Match against Title case words (one upper case followed by lower case letters).
; ([A-Z]+(?=([A-Z][a-z])|($)|([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's followed by the end of the string or a number.
newString := RegExReplace(oldCamelOrPascalString, "((^[a-z]+)|([0-9]+)|([A-Z]{1}[a-z]+)|([A-Z]+(?=([A-Z][a-z])|($)|([0-9]))))", "$1 ")
newString := Trim(newString)
А вот несколько примеров того, как строка с числами преобразуется с помощью этого регулярного выражения:
- myVariable123 => моя переменная 123
- my2Variables => мои 2 переменные
- The3rdVariableIsHere => 3-я переменная здесь
- 12345NumsAtTheStartIncludedToo => 12345 Nums при запуске тоже слишком