oracle REGEXP_REPLACE - 仅当包含在 () 中时才从字符串中删除新行 \n
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/15165274/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
REGEXP_REPLACE - remove new line \n from string ONLY if is enclosed in ()'s
提问by TA Nguyen
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.
我正在尝试使用 REGEXP_REPLACE 替换字符串中的所有新行 (\n),只有一个例外 - 它们必须括在括号中才能被替换。
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...
非常感谢...
采纳答案by Egor Skriptunoff
var2 := regexp_replace(var1, '((\)|^).*?(\(|$))|'||chr(10), '', 1, 0, 'n');