【问题标题】:Regular Expression to match markdown and regular href sources from specific domain(s)正则表达式匹配来自特定域的 markdown 和正则 href 源
【发布时间】:2018-12-14 05:38:28
【问题描述】:

我正在尝试将一些内容附加到查询字符串到托管在文件选择器上的各种资产,这些资产来自几个特定域,其中一些已经包含查询字符串。所有其他 URL 应保持不变。

例如,我们可能在markdown中有以下内容:

![image](https://www.filepicker.io/api/file/12x3DD5667dxfjdf/convert?w=600)

我们也可以

<img src="https://www.filepicker.io/api/file/someotherfile" />

或者

<a href='https://www.filestack.com/api/file/anothersdf?sdf=3&dfdf=1'>link</a>

目前我只是尝试匹配一个域,但我有以下不匹配所有情况的正则表达式:

我不想匹配对其他域的任何引用。

我在以下方面取得了喜忧参半:

/(https:\/\/www\.filepicker.io\/api\/file\/[a-zA-Z0-9]+(\/convert)*[^)])$/is

【问题讨论】:

标签: php regex preg-match


【解决方案1】:

这将符合您的要求:

 /(https?:\/\/www\.(?:filepicker\.io\/|filestack\.com\/)api\/file\/[\w+?&=\/]+)/

https://regex101.com/r/DA8Gok/2/

但正则表达式(本身)不太适合解析任何类型的结构化数据。而是制作一个词法分析器/解析器。

以下是我写的一些例子:

https://github.com/ArtisticPhoenix/MISC/tree/master/Lexers

http://artisticphoenix.com/2018/11/11/output-converter/

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-12-20
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-06-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多