gpt4 book ai didi

regex - 匹配 URL 的路径,减去文件扩展名

转载 作者:行者123 更新时间:2023-12-04 01:24:06 30 4
gpt4 key购买 nike

这种情况下最好的正则表达式是什么?

鉴于此网址:

http://php.net/manual/en/function.preg-match.php

我应该如何选择(但不包括)之间的所有内容 http://php.net.php :

/manual/en/function.preg-match

这是一个 Nginx配置文件。

最佳答案

像这样:

if (preg_match('/(?<=net).*(?=\.php)/', $subject, $regs)) {
$result = $regs[0];
}

解释:
"
(?<= # Assert that the regex below can be matched, with the match ending at this position (positive lookbehind)
net # Match the characters “net” literally
)
. # Match any single character that is not a line break character
* # Between zero and unlimited times, as many times as possible, giving back as needed (greedy)
(?= # Assert that the regex below can be matched, starting at this position (positive lookahead)
\. # Match the character “.” literally
php # Match the characters “php” literally
)
"

关于regex - 匹配 URL 的路径,减去文件扩展名,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8313941/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com