私は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 => and This One Is Camel 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 開始時の数値も含まれる