REGEXP_REPLACE-仅在()中包含的情况下,才从字符串中删除新行\ n [英] REGEXP_REPLACE - remove new line \n from string ONLY if is enclosed in ()'s

查看:520
本文介绍了REGEXP_REPLACE-仅在()中包含的情况下,才从字符串中删除新行\ n的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用REGEXP_REPLACE替换字符串中的所有新行(\ n),但有一个例外-必须将其括在要替换的括号中.

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.

示例:

字符串前:

'a\n, b\n, c (a\n, b, c\n), d\n, e'
var1 := 'a
, b
, c (a
, b, c
), d
, e'

字符串后:

'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.

非常感谢...

推荐答案

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

这篇关于REGEXP_REPLACE-仅在()中包含的情况下,才从字符串中删除新行\ n的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆