【发布时间】:2020-01-28 21:12:17
【问题描述】:
当它不在模式 <a href 和 a> 之间时,我试图用 "group1" 替换这个词。下面的查询替换了所需模式中的“组”。如何替换模式外的单词?
with t as (
select '<a href Part of the technical Network Group www.tech.com/sites/ hh a> group' as text from dual
union all select '<a href mean www.tech.technical Network a>' as text from dual
union all select 'www.tech.tech///technical <a href Network Group a>' as text from dual)
select regexp_replace(text,'group','group1',1,0,'i')
from t
WHERE REGEXP_LIKE(text,'<a href.*group.*a>','i')
第一行的预期输出是(“组”一词出现在模式的内部和外部)。期望只是替换外面的那个)
<a href Part of the technical Network group www.tech.com/sites/ hh a> group1
【问题讨论】:
-
请在此处向我们展示您期望的确切输出。
-
一般来说,判断
group是出现在锚点或任何其他HTML标签的内部还是外部,超出了正则表达式的能力(它肯定超出了 Oracle 内部运行的正则表达式风格)。因此,我建议您将 HTML 内容从 Oracle 导出到更适合此类工作的工具,例如 Java 或 C#。 -
谢谢你的建议,蒂姆。我会检查更多选项。
标签: sql oracle pattern-matching regexp-replace regexp-like