1

I have a string 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 \n.

So the example would convert to

Text Text Text\nText Text Text T5df Tdfcv Text\nNeu

I am using ICU regex.

I tried "[\p{Upper}]", which matches all uppercase literals, but not with a preceding lowercase in the same word.

Also I need to know what to replace it with as regex.

How do I accomplish that?

Aurelius Schnitzler
  • 511
  • 2
  • 8
  • 18
  • 1
    Use `(?<=\p{Ll})(?=\p{Lu})`, replace with a `\n`. – Wiktor Stribiżew Jan 05 '21 at 12:37
  • That works. But how did you come up with that? – Aurelius Schnitzler Jan 05 '21 at 12:38
  • 2
    It is simple: `(?<=\p{Ll})` is a positive lookbehind matching a location immediately after lowercase letter and `(?=\p{Lu})` is a positive lookahead that requires an uppercase letter immediately to the right of the current location. So, it matches a location in a string between a lower- and an uppercase letter (because lookarounds do not advance the regex index when their patterns are matched). – Wiktor Stribiżew Jan 05 '21 at 12:44

0 Answers0