4

I want replace EVERY space inside EMPTY single quotation marks against the same number of CHR(32).

condition: REGEX has to match only this case - not for cases with signs between single quotation marks!

important hint: the construct, where to replace the spaces between will begin in every case with:

\|\|\s*'

and ends (in every case) with (according to Row 1+2):

'\s*\|\|

I use for search pattern:

'(\s)+'

and for replacement:

CHR\(32\)

But, this replaces all spaces against only ONE CHR(32)!

Following example:

vpl_text := to_char(vpl_text_old) || '    ' ||...;
vpl_text := to_char(vpl_text_old) || '' ||...;
(3)' WHERE   a.object_type IN (' 'TABLE'', ''MATerialIZED VIE3W'   ')  '   
(4) WHERE    a.object_type IN (' 'TABLE'', ''MATerialIZED VIE3W'   ')

my incomplete result:

vpl_text := to_char(vpl_text_old) || CHR(32) ||...;
vpl_text := to_char(vpl_text_old) || '' ||...;
(3)' WHERE   a.object_type IN (CHR(32)TABLE'', ''MATerialIZED VIE3WCHR(32))  '   
(4) WHERE    a.object_type IN (CHR(32)TABLE'', ''MATerialIZED VIE3WCHR(32))

target result:

vpl_text := to_char(vpl_text_old) || CHR(32) || CHR(32) || CHR(32) || CHR(32) ||...;
vpl_text := to_char(vpl_text_old) || '' ||...;
(3)' WHERE   a.object_type IN (' 'TABLE'', ''MATerialIZED VIE3W'   ')  '   
(4) WHERE    a.object_type IN (' 'TABLE'', ''MATerialIZED VIE3W'   ')

Row 3 + 4 has to stay unchanged!

("(3)" and "(4)" are not part of this construct - were only used for explanation!) .

This topic is caused as an alternative for: replace characters in notepad++ BUT exclude characters inside single quotation marks(4th)

How can I define in notepad++ the replacement REGEX correct?

Community
  • 1
  • 1
ora_job
  • 93
  • 5

2 Answers2

3

You can use the \G anchor to continue where the previous match ended. Something like this:

(?:'|\G(?!^))\s(?=\s*')'?

And replace with CHR\(32\). See test at regex101.


  • (?: opens a non capture group. Matching literal ' single quote | or:

  • \G(?!^) continue where previous match ended. Without (?!^) \G would also match start.

  • \s replaces a whitespace (?=\s*') if followed by any amount of space and another '

  • '? the ending ' optional to maintain \G sequence.

Reference - What does this regex mean

Community
  • 1
  • 1
Jonny 5
  • 11,051
  • 2
  • 20
  • 42
  • your REGEX does not replace the single quotation marks. If I use this REGEX without \K - only the ending single quote will replaced, the opening (as you already wrote) not. Can you try to adjust your solution? Much thanks in advance! – ora_job Aug 31 '15 at 09:25
  • @ora_job I've overlooked that! Please check [if it meet demands now](https://regex101.com/r/hN0xR7/1). – Jonny 5 Aug 31 '15 at 10:19
0

I have found a solution (I adapted Jonny5's answer):

(after I changed and extended this question, (sorry to Jonny5))

search pattern:

(?:\|\|\s*'|\G(?!^))\s(?=\s*')'?

replacement pattern:

\|\| CHR\(32\)
ora_job
  • 93
  • 5