如何为以.php结尾的文件制作正则表达式? [英] How to make a regex for files ending in .php?
问题描述
我正在尝试编写一个非常简单的正则表达式,以匹配不以.php结尾的任何文件名.我想出了以下...
I'm trying to write a very simple regular expression that matches any file name that doesn't end in .php. I came up with the following...
(.*?)(?!\.php)$
...但是,它匹配所有文件名.如果有人能指出正确的方向,我将不胜感激.
...however this matches all filenames. If someone could point me in the right direction I'd be very grateful.
推荐答案
几乎:
.*(?!\.php)....$
最后四个点确保在检查预视时有要向前看的东西.
The last four dots make sure that there is something to look ahead at, when the look-ahead is checked.
因为您对整个比赛都感兴趣,所以不需要使用括号.
The outer parentheses are unnecessary since you are interested in the entire match.
不需要.*?
是不必要的,因为回溯四步比检查每一步的以下条件更有效.
The reluctant .*?
is unnecessary, since backtracking four steps is more efficient than checking the following condition with every step.
这篇关于如何为以.php结尾的文件制作正则表达式?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!