Search code examples
regexpcre

How to deactivate the uppercase transformation?


Starting from a list of strings:

Hello World 1
Hello World 2

I'm trying to obtain the following result, with the original string in uppercase, followed by the original string (original case).

HELLO WORLD 1 = Hello World 1
HELLO WORLD 2 = Hello World 2

I've tried using the uppercase transformation but all characters that follow the \U are outputed in upper case:

  • Search for: (.*)\n
  • Replace with: \U$1 = $1\n

Output:

HELLO WORLD 1 = HELLO WORLD 1
HELLO WORLD 2 = HELLO WORLD 2

Link to online example.


Solution

  • It can be done by using the \E (Terminate Transformation).

    • Search for: (.*)\n

    • Replace with: \U$1\E = $1\n

    It also works with other transformations like \L (Lowercase Transformation)

    Link to online example