【问题标题】:Apache: mod_substitute rule to strip out all .html hyperlinks in a textApache:mod_substitute 规则去除文本中的所有 .html 超链接
【发布时间】:2018-06-21 17:37:36
【问题描述】:
Substitute "s|<a(.*)href=\"/(.*)\.html\"(.*)>|<a$1href=\"/$2\"$3>|i"

这是我正在使用的替代规则,但看起来如果在一个段落中我有多个 href,则只有尾随的一个会被去除 html 扩展名。以前的 href 没有影响。

【问题讨论】:

    标签: html regex apache httpd.conf substitution


    【解决方案1】:

    (.*) 表示这一行中的字符尽可能多,因此在匹配第一个&lt;a 后,它将搜索最远的href 后续。如果添加 ?在 * 之后,它将寻找与(.*?) 匹配的最小字符串,该字符串仍允许其余字符串匹配。

    Substitute "s|<a(.*?)href=\"/(.*?)\.html\"(.*?)>|<a$1 href=\"/$2\"$3>|i"
    

    【讨论】:

      猜你喜欢
      • 2016-06-01
      • 2010-09-07
      • 2023-03-23
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-06
      • 2018-04-03
      • 1970-01-01
      相关资源
      最近更新 更多