我正在使用 oracle10g
。
我想从句子中删除特定单词的所有出现,但我不想删除包含其他字符(a-z或A-Z)之间的任何其他单词。
例如,以下是一句话,我想要删除其中的some
:
some text, 123 someone, another text some1
期望输出:
text, 123 someone, another text
请注意,如果“some”单词包含除“A-Z”和“a-z”之外的任何其他字符,则我还想将其删除,并且这些字符在“some”之前或之后存在。下面是我迄今为止尝试过的方法:
select replace('some text, 123 someone, another text some1','some','')
from dual;
我得到的输出是:
text, 123 one, another text 1
在上面的输出中,我希望
someone
不被替换,而some1
应该完全被替换。我应该如何实现这一点?任何建议都将不胜感激。 编辑:为了清晰起见,这是我要寻找的另一个示例:
some other text someone other text, someB some1 some.
输出应该是:
other text someone other text, someB
从上面的句子中我们可以看到,someB
没有被删除是因为它之间有字符a-z
。
而some1
和some.
则被删除了,因为它们之间没有a-z
。
编辑2
如果我使用正则表达式:
select REGEXP_REPLACE('some text, 123 someone, another text some1','[^a-zA-Z]','')
from dual
我得到的输出是:
sometextsomeoneanothertextsome
期望输出:
sometextsomeoneanothertext
请注意,我希望字符串中的
some1
也被移除,因为它包含除A-Z
之外的其他字符。欢迎使用regex
进行回答。
some
,不需要处理顺序。每个some
都不包含在开头和结尾处没有A-Z
和a-z
之间的单词。 - Bhushan