简体   繁体   中英

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

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'
var1 := 'a
, b
, c (a
, b, c
), d
, e'

After string:

'a\n, b\n, c, (a b c), d\n, e'
var2 := '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...

var2 := regexp_replace(var1, '((\)|^).*?(\(|$))|'||chr(10), '\1', 1, 0, 'n');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM