Javascript cloudinary url的正则表达式组
我试图捕获url的不同部分,而忽略有时出现的部分 我尝试过使用和扩展这里的正则表达式,但运气不佳 举个例子Javascript cloudinary url的正则表达式组,javascript,regex,cloudinary,Javascript,Regex,Cloudinary,我试图捕获url的不同部分,而忽略有时出现的部分 我尝试过使用和扩展这里的正则表达式,但运气不佳 举个例子 https://res.cloudinary.com/test-site/image/upload/v1619174590/folder/path/cjtdn73cleqagpy4fqza.jpg https://res.cloudinary.com/test-site/image/upload/ar_1:1,c_fill,f_auto,g_auto,w_700/v1619174590/
https://res.cloudinary.com/test-site/image/upload/v1619174590/folder/path/cjtdn73cleqagpy4fqza.jpg
https://res.cloudinary.com/test-site/image/upload/ar_1:1,c_fill,f_auto,g_auto,w_700/v1619174590/folder/path/cjtdn73cleqagpy4fqza.jpg
https://res.cloudinary.com/test-site/image/facebook/fb_id
res.cloudinary.com:主机
测试站点:cloudname
上传/facebook:资源类型
v1619174590/rg/collective/media/cjtdn73cleqagpy4fqza.jpg:id
我需要忽略/upload/和/v之间的所有内容,我已经使用//upload/*?\b(?=v1)/,完成了这一点,但它不考虑资源类型是否为facebook,并且没有可以使用的/v123
https?:\/\/(?[^\/]+)\/(?[^\/]+)\/[^\/]+\/(?[^\/]+)(?:\/[^\/,]*,[^\/]*)?\/(?*)
https?:\/\/([^\/]+)\/([^\/]+)\/[^\/]+\/([^\/]+)(?:\/[^\/,]*,[^\/]*)?\/(*)
第一个正则表达式符合支持命名捕获组的ECMAScript 2018+标准,第二个正则表达式只包含常规的、编号的捕获组
看
细节
-https?:\/\/
或https://
http://
-组1(主机):除([^\/]+)
-/
-a\/
字符/
-组2(云名称):除([^\/]+)
/
-\/[^\/]+\/
,除/
和/
以外的任何一个或多个字符/
-组3(资源类型):除([^\/]+)
/
-可选的(?:\/[^\/,]*,[^\/]*)?
-a\/
字符/
-除[^\/,]*
和/
以外的零个或多个字符,
-逗号,
-除[^\/]*
/
-a\/
字符/
-组4(id):字符串的其余部分(.*)
(https?)\:\/\/(res.cloudinary.com)\/([^/]+)\/(image|video|raw)\/(upload|authenticated)\/(.*)\/(v[0-9]+)\/(.+)(?:\.[a-z]{3})?
(https?)\:\/\/(res.cloudinary.com)\/([^/]+)\/(image|video|raw)\/(upload|authenticated)\/(.*)\/(v[0-9]+)\/(.+)(?:\.[a-z]{3})?
不太清楚,你的意思是你想要
https?:\/\/(?[^\/]+)\/(?[^\/]+)\/[^\/]+\/[^\/]+(?[^\/]+)(?:\/[^\/,]*,[^\/]*)?\/(?*
?看见也就是说,在resource\u type
之后不包括一个带有逗号的部分。似乎您的演示程序在我这边测试过的案例中有效。太好了,我发布了。