【问题标题】:Regex with avoidation of markdown避免降价的正则表达式
【发布时间】:2021-05-30 19:32:29
【问题描述】:

模式为:/(?:https?://)?(?:[^.]+.)?momento360.com/e/(.*)?/i

此正则表达式模式返回网站后 URL 的剩余部分。

[click here](https://momento360.com/e/uc/1478291a8dd94a8198339f1ffe4b97be?utm_campaign=embed&utm_source=other&size=medium)


https://momento360.com/e/u/a9b53aa8f8b0403ba7a4e18243aabc66


https://momento360.com/e/uc/1478291a8dd94a8198339f1ffe4b97be?upload-key=e84e1fb3567546a885a2a223bde6ef32

但现在我想忽略[click here](...) Markdown 中的字符串

【问题讨论】:

  • 你好@WiktorStribiżew。谢谢你。它有效。

标签: javascript php regex laravel


【解决方案1】:

你可以使用

\[click here]\(http[^()]*\)(*SKIP)(*F)|(?:https?:\/\/)?(?:[^.]+\.)?momento360\.com\/e\/(.*)

请参阅regex demo

这里,

  • \[click here]\(http[^()]*\)(*SKIP)(*F) - 匹配 [click here](...) 子字符串并跳过此匹配,开始在发生故障的位置搜索新匹配
  • (?:https?:\/\/)?(?:[^.]+\.)?momento360\.com\/e\/(.*) - 匹配可选的 http://https://,然后匹配任意 1+ 字符的可选序列,而不是点,然后是点,然后是 momento360.com/e/ 字符串,然后将任何零个或多个字符捕获到组 1除了换行符,尽可能多。

【讨论】:

    【解决方案2】:

    如果您要转义的所有网址都在() 中,而其他网址则没有,您可以使用这个:

    [^(]https?:?(?:[^.]+.)?momento360.com/e/(.*)?
    

    【讨论】:

      猜你喜欢
      • 2016-12-07
      • 1970-01-01
      • 1970-01-01
      • 2012-02-07
      • 2016-07-17
      • 1970-01-01
      • 2018-03-28
      • 2012-01-07
      • 1970-01-01
      相关资源
      最近更新 更多