如何仅替换Oracle中文本的某些部分?

问题描述 投票:0回答:1

我正在尝试替换文本中的某些单词。但是,如果单词是url的一部分,则不希望替换该单词。例如:技术一词。替换为两个地方(包括url)。

select regexp_replace('Part of the Technical Network Group https://technical.com/sites/','technical','tech',1,0,'i')
from dual

输出:

Part of the tech Network Group https://tech.com/sites/

预期输出:

Part of the tech Network Group https://technical.com/sites/

sql oracle replace string-matching regexp-replace
1个回答
0
投票

您可以在替换中添加一个空格。

select regexp_replace('Part of the Technical Network Group https://technical.com/sites/',
                      ' technical', (I added a blank space before)
                      'tech',1,0,'i')
from dual

由于URL永远不会有''(空格),因此它将永远不会被替换。

希望这可以解决您的问题。

© www.soinside.com 2019 - 2024. All rights reserved.