Home > database >  Make all lowercase except text between speech marks
Make all lowercase except text between speech marks

Time:09-07

Taking this simple sample SQL:

WITH my_data as
    (SELECT 'XX_abc_123' label from DUAL UNION ALL
     SELECT 'XX_SWU_541324_FFF' from DUAL)
SELECT label from MY_DATA;

Is there a way to write a Regular Expression in Notepad to make all text lower case, but to not change the case of any text between the '' marks, resulting in this:

with my_data as
    (select 'XX_abc_123' label from dual union all
     select 'XX_SWU_541324_FFF' from dual)
select label from my_data;

I have tried this:

  1. Find: ([a-z])
  2. Replace: \L$1\E

But that makes everything lowercase:

with my_data as
    (select 'xx_abc_123' label from dual union all
     select 'xx_swu_541324_fff' from dual)
select label from my_data;

CodePudding user response:

You can use

Find What: '[^']*'|([A-Z])
Replace With: (?1\L$1:$0)

Make sure you select Regular expression and Match Case.

Details:

  • '[^']*' - matches ', zero or more chars other than ' and then a '
  • | - or
  • ([A-Z]) - capture into Group 1 an ASCII uppercase letter.

The (?1\L$1:$0) means that the replacement is a lowercased Group 1 value if Group 1 matched, else, the replacement is the whole match.

See the demo screenshot:

enter image description here

CodePudding user response:

In Notepad you might use SKIP FAIL to skip the matches for the single quote parts, and get matches for uppercase chars only.

'[^']*'(*SKIP)(*F)|[A-Z]
  • '[^']*' Match from '....'
  • (*SKIP)(*F) SKIP the match
  • | Or
  • [A-Z] Match a single uppercase char A-Z

In the replacement use the match $0

\L$0\E

enter image description here

  • Related