Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
313 views
in Technique[技术] by (71.8m points)

regex - Split mixed upper and lowercase in the same word into two lines

I have a string in cells that is lacking new lines.

It looks like this:

Text Text TextText Text Text T5df Tdfcv TextNeu

In other words:

If there is a change from Lowercase to Uppercase within a word, this is where a new line should be inserted as .

So the example would convert to

Text Text Text
Text Text Text T5df Tdfcv Text
Neu

Resp.:

Text Text Text
Text Text Text T5df Tdfcv Text
Neu

I found

String[] r = s.split("(?=\p{Lu})");

I tried REGAUS(F2;"(?=\p{Upper})";" ";"g") yet I get a 502, as something is wrong with the regex.

Which formula do I need for calc to do this?


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

With english formula names, the following formula will do the trick:

=REGEX(A1;"([:lower:])([:upper:])";"$1"&CHAR(10)&"$2";"g")

Same on multiple lines for sake of readability:

    =REGEX(
        A1;
        "([:lower:])([:upper:])";
        "$1" & CHAR(10) & "$2";
        "g"
    )

It matches a lower-case letter followed by an upper-case letter, and inserts a newline using the CHAR() function.

You'll have to adapt the line heigth manually, otherwise you will see only "Neu" (the last line).

For localised formula names (german), it would be:

=REGAUS(A1;"([:lower:])([:upper:])";"$1"&ZEICHEN(10)&"$2";"g")

I would have expected that inserting " " should work, too, but i did'nt manage got get it working, thus the recourse to CHAR(10).


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...