【问题标题】:preg_match_all find string not "http" and after #preg_match_all 查找字符串不是“http”并且在#之后
【发布时间】:2016-02-23 08:30:30
【问题描述】:

我需要找到一个不包含httpshttp,但在#之后的字符串
演示:

#abc => find.
http://google.com/#abc => not find.

我的代码是在 # 之后查找内容 preg_match_all("/#([^\s]+)/", $content, $matches);

【问题讨论】:

  • 请在您的实际输入和输出字符串上更加精确。您的目标可以通过多种方式实现。

标签: regex preg-match-all


【解决方案1】:

这应该适合你

^(http://)(?#)

【讨论】:

    【解决方案2】:

    我相信您首先要确保该字符串是一个 URL,然后才能获得 hashbang 后面的所有内容? (包括hashbang)。那么我相信这个带有非捕获组的正则表达式会起作用:

    preg_match_all('/^(?:https*:\/\/.*)(#.*)$/', $url, $matches);
    

    我怀疑你正在使用 php :)

    【讨论】:

      【解决方案3】:
      ^(?!https?://).*?$
      

      你可以看这里:regax

      【讨论】:

        猜你喜欢
        • 2022-01-11
        • 1970-01-01
        • 2019-07-22
        • 1970-01-01
        • 2012-02-10
        • 2016-03-23
        • 2014-12-03
        • 1970-01-01
        • 2014-11-14
        相关资源
        最近更新 更多