用于匹配来自特定域的降价和常规 href 源的正则表达式

Regular Expression to match markdown and regular href sources from specific domain(s)

我正在尝试将查询字符串中的内容附加到文件选择器上托管的各种资产,这些资产来自几个特定域,其中一些已经包含查询字符串。所有其他 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

这将符合您的要求:

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

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

但是 Regex 不太适合(就其本身)解析任何类型的结构化数据。而是制作 lexer/parser.

以下是我写的一些示例:

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

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