1

In

replace characters in notepad++ BUT exclude characters inside single quotation marks(2nd)

"Jonny 5" solved this question - BUT - if I have a construct like this:

SELECT column_name FROM table_name WHERE column_name IN ('A' , 'st9u' ,'Meyer', ....);
WHERE    a.object_type IN (' 'TABLE'', ''MATerialIZED VIE3W'   ')
vpl_text := IS_GOING_SMALL_CORRECT

(1) vpl_text := TO_CHAR(vpl_text_old) || '    ' ||...;
-- ------
vpl_text := STAYS_UPPER_ERROR

(2) vpl_text := TO_CHAR(vpl_text_old) || '' ||...;
-- ------

vpl_text := IS_GOING_SMALL_CORRECT

then the target should be:

select column_name from table_name where column_name in ('A' , 'st9u' ,'Meyer', ....);
where    a.object_type in (' 'TABLE'', ''MATerialIZED VIE3W'   ')
vpl_text := is_going_small_correct

(1) vpl_text := to_char(vpl_text_old) || '    ' ||...;
-- ------
vpl_text := stays_upper_error

(2) vpl_text := to_char(vpl_text_old) || '' ||...;
-- ------

vpl_text := is_going_small_correct

but the result is (The rest is o.k.!):

:
-- ------
vpl_text := STAYS_UPPER_ERROR

(2) vpl_text := TO_CHAR(vpl_text_old) || '' ||...;
-- ------
:

conditions: (same like in) replace characters in notepad++ BUT exclude characters inside single quotation marks(2nd)

It happens also, if I exchange the lines (1) and (2)!

How can I change this REGEX in notepad++ that ALL UPPER signs change to lower signs - exclude inside single quotation marks?

Community
  • 1
  • 1
ora_job
  • 103
  • 7

1 Answers1

1

The actual problem with the previous regex is that ' ' was considered as an opening delimiter, and the whole text from ' ' up to '' was "protected" with the subroutine call.

Use

'\s*(?0)?(?=\w)[^']*'\K|(\w+)

The (?=\w) look-ahead makes sure that after the innermost starting ' is followed by a word character. If there can be again a space, you may replace this look-ahead with (?=\s*\w).

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
  • Much thanks for your effort - but - if I insert, direct behind (1), a construct like this 'WHERE a.object_type IN (' 'TABLE'', ''MATerialIZED VIE3W' ') ' (single quotation marks at beginning (in front of WHERE) and end (behind last right parenthesis)) then the problem stays the same (also if I replace this look-ahead with (?=\s*\w)) (This construct is not artificial - it appears in this kind in practice!) (general it happens everywhere if I use this construct additional in this text) (without this construct, your solution runs brilliant!) Have you any solution? – ora_job Sep 02 '15 at 11:14
  • Do you mean the string `'WHERE a.object_type IN (' 'TABLE'', ''MATerialIZED VIE3W' ') '`? It is all inside `'...'`. It should be left intact acc. to the requirements. Or not? – Wiktor Stribiżew Sep 02 '15 at 11:17
  • Much thanks for your effort - but - if I insert, direct behind **(1)**, a construct like this `'WHERE a.object_type IN (' 'TABLE'', ''MATerialIZED VIE3W' ') '` **(single quotation marks at beginning (in front of WHERE) and end (behind last right parenthesis))** then the problem stays the same (also if I replace this look-ahead with (?=\s*\w)) (This construct is not artificial - it appears in this kind in practice!) (general it happens everywhere if I use this construct additional in this text) (without this construct, your solution runs brilliant!) Have you any solution? – ora_job Sep 02 '15 at 11:23
  • Try `'\K([^']*)(?='\s*'(?=\w)[^']*'\s*')|'\s*(?0)?(?=\w)[^']*'\K|(\w+)` with `\L\1\2` replacement. – Wiktor Stribiżew Sep 02 '15 at 11:26
  • Yes, I mean this string - during I tried to format the comment, our answers overlapped each other. (This string is the Problem!) – ora_job Sep 02 '15 at 11:26
  • The Problem stays the same, exclude the **WHERE** and **IN**, inside this construct are lowered - that's not the target - all words inside **'...'** have to be **untoched**. – ora_job Sep 02 '15 at 11:37
  • Please check the updated answer and let me know what is wrong. Your current explanation is not clear: `' words ' 'SomeNames'' '` - what is inside `'...'`? What should be changed, what not? – Wiktor Stribiżew Sep 02 '15 at 11:43
  • I wrote **BEHIND (1)**, and meant direct after 1st `'-- -----'` (inacc. from my side, sorry) - then, as I wrote already, the problem stays the same, exclude the **WHERE.... (p1)** (p...problem). In your updated answer it runs, exclude the **WHERE.... (p2)**. If I move this statement to other positions, then we have (p1) or (p2). The REGEX has to be **independent of position of this construct**... (It may come many times and everywhere...) (**'...'** ... means everything inside single quotation marks **(independent of number of nesting) has to be unchanged!)** – ora_job Sep 02 '15 at 12:16
  • (additional comment) The maximal nesting of quotation marks is **3** !(as shown in this construct) – ora_job Sep 02 '15 at 12:28
  • I do not think it is solvable at all with regex then. – Wiktor Stribiżew Sep 02 '15 at 13:42