Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/20.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
REGEX:如何通过REGEX匹配/选择特定链接_Regex_String - Fatal编程技术网

REGEX:如何通过REGEX匹配/选择特定链接

REGEX:如何通过REGEX匹配/选择特定链接,regex,string,Regex,String,我不知道关于Regex的这些信息。我想选择所有的链接,我给下面的例子 http://example.com/file/3843732a6e531/filename.rar http://example.com/file/24af962a61126/filename.zip http://example.com/file/3843732a6e531/filename-part1.rar 所以我想选择所有以http://example.com并以.rar或.zip结尾。以下是正则表达式和一些解释:

我不知道关于Regex的这些信息。我想选择所有的链接,我给下面的例子

http://example.com/file/3843732a6e531/filename.rar
http://example.com/file/24af962a61126/filename.zip
http://example.com/file/3843732a6e531/filename-part1.rar

所以我想选择所有以
http://example.com
并以
.rar
.zip
结尾。以下是正则表达式和一些解释:

^http:\/\/domain\.com(.*)\.(?:zip|rar)$
^
就是说它需要从

http:
基本匹配
http:
(并且区分大小写)

我们现在想匹配链接的2
/
,但是
/
在正则表达式中是一个分隔符,因此需要通过在要转义的字符前面放置一个
\
来转义它

这就是为什么我们有
\/\/

我们想匹配域名的
。但正如
/
在正则表达式中已经表示任何字符,所以我们也需要对其进行转义。 这就是为什么我们有
\。

您希望它检查链接是否以.zip或.rar结尾。 这已经结束了

(?:zip|rar)

请尝试以下正则表达式:

(http:\/\/domain\.com\/.*?(?:rar|zip))

这是在的描述。

这应该很容易。你试过什么了吗?没有,正如我说的,我对正则表达式不专业。对不起,我的英语不好。等待答案。感谢您提供的这些精彩信息。我试过了,但没有选择。有什么想法吗这是因为当你正在尝试文本时,你在代码中保留了<代码> ^ < /代码>和<代码> $>代码。删除他们,它应该工作!或者进行多行全局搜索-[在此处选中]。()但它选择以下部分:“/file/24af962a61126/filename”和“/file/3843732a6e531/filename-part1”。我想选择所有以字符串开头和结尾的链接,我在第一个问题中说,一个用户回答并删除了他自己的消息。他的密码有效,但我不知道他为什么删除了他的答案。他的密码:谢谢你的回复。多亏了你的回答,我才明白:)