【问题标题】:How to replace the word which is not placed between a pattern using Oracle REGEXP and not the same word inside the pattern?如何使用 Oracle REGEXP 替换未放置在模式之间的单词和模式内的不同单词?
【发布时间】:2020-01-28 21:12:17
【问题描述】:

当它不在模式 <a hrefa> 之间时,我试图用 "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


【解决方案1】:

如果我没有将阅读本文的每个人都指向有关使用正则表达式解析 HTML 的权威文章,那我将是失职: RegEx match open tags except XHTML self-contained tags

【讨论】:

  • 谢谢,加里。这很有帮助。
猜你喜欢
  • 2020-02-01
  • 1970-01-01
  • 1970-01-01
  • 2021-10-08
  • 2020-07-11
  • 2020-01-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多