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.
Almost:
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.