Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

REGEXP_REPLACE - remove new line \n from string ONLY if is enclosed in ()'s

994289Mar 1 2013 — edited Mar 1 2013
Hello all,

I'm trying to use REGEXP_REPLACE to replace all new line (\n) from a string with one exception - they MUST be enclosed in parentheses to be replaced.

Example:

Before String:
'a\n, b\n, c (a\n, b, c\n), d\n, e'

(equivalent)
var1 := 'a'||chr(10)||', b'||chr(10)||', c (a'||chr(10)||', b, c'||chr(10)||'), d'||chr(10)||', e'

(or simple substitute with newline as below)
var1 := 'a
, b
, c (a
, b, c
), d
, e'

After string:
'a\n, b\n, c, (a b c), d\n, e'

or console display:
'a
, b
, c (a, b, c), d
, e'

I know there must be a clean regular expression pattern that can do this - but I can't get my head around it.

thanks very much...

Edited by: 991286 on Mar 1, 2013 11:35 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 29 2013
Added on Mar 1 2013
6 comments
3,525 views