要匹配的正则表达式和 select 个特定网址

RegEx to match and select specific URLs

我正在访问包含这些 URL 的网站;

https://flyheight.com/videos/ybb347
https://flyheight.com/videos/yb24os
https://flyheight.com/public/images/videos/793f77362f321e62c32659c3ab00952d.png
https://flyheight.com/videos/5o6t98/#disqus_thread

我需要一个仅 select 这些 URL 的正则表达式

https://flyheight.com/videos/yb24os
https://flyheight.com/videos/ybb347

这是我目前得到的 ^(?!images$).*(flyheight.com/videos/).*

PCRE:^https?:\/\/flyheight\.com\/videos\/[a-z0-9]{6}$

https://regex101.com/r/vM31MK/1

也许这也适用于您的语言: ^https?://flyheight\.com/videos/[a-z0-9]{6}$

This simple expression 可能会这样做,因为您想要的所有输出都以 y 开头:

\/(y.*)

但是,如果您希望为其添加额外的边界,您可以这样做。例如,this 会加强左边界:

flyheight.com\/videos\/(y.*)

或者您可以添加一个字符列表,类似于 this

flyheight.com\/videos\/([a-z0-9]+)

您还可以向所需输出添加量词,类似于 this expression

flyheight.com\/videos\/([a-z0-9]{6})

并且您可以简单地增加和添加您想要的任何边界并捕获您想要的 URL,并让其他人失败。

您可能希望根据您想要的引擎使用 this tool 和 change/edit/modify 您的表达式:

^(.*)(flyheight.com\/videos\/)([a-z0-9]{6})$

这张图显示了它是如何工作的,你可以测试更多的表达式here

我不太确定这是否是您要查找的内容,但您可以使用以下内容:

^(?!images$).*(flyheight.com/videos/)([^/]+)$

这个想法是它会匹配您拥有的第一部分,然后匹配一个或多个不是斜杠的字符 ([^/]+)

如果您的字符串末尾可能包含或不包含 /(例如,您有 https://flyheight.com/videos/yb24os or https://flyheight.com/videos/yb24os/),您可以尝试以下操作:

^(?!images$).*(flyheight.com/videos/)([^/]+)/?$

here are my results on regexr.