【问题标题】:RegEx find all matches not present in the following set正则表达式查找以下集合中不存在的所有匹配项
【发布时间】:2020-07-17 04:14:59
【问题描述】:

如何对特定匹配中不存在的点符号执行正则表达式替换(例如在图像 HTML 标记中)

str = "Hi. the symbol before me is my match target <img src='http://skip.these.dots/and.this.as.well' alt='me.three' /> but still match this."

被替换为(例如)*符号

res = "Hi* the symbol before me is my match target <img src='http://skip.these.dots/and.this.as.well' alt='me.three' /> but still match this*"

【问题讨论】:

    标签: regex regex-group regexp-replace


    【解决方案1】:

    试试这个:

    \.(?![^<]*\/>)
    

    Demo

    正则表达式引擎执行以下操作。

    \.      # match period
    (?!     # begin negative lookahead
      [^<]* # match 0+ chars other than '<'
      \/>   # match '/>'
    )
    

    如果在句号之后遇到/&gt; 而没有任何中间的&lt;,则负前瞻将失败,这意味着句点必须介于&lt;/&gt; 之间。

    您希望用* 替换句点的每个匹配项。具体操作方式取决于您使用的语言,但这无疑是简单明了的。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-12-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2011-03-31
      • 2013-01-19
      • 2015-04-29
      相关资源
      最近更新 更多