How to make a regex for files ending in .php?

前端 未结 3 1652
猫巷女王i
猫巷女王i 2020-12-21 15:02

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)$         


        
3条回答
  •  情话喂你
    2020-12-21 15:18

    Almost:

    .*(?!\.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.

提交回复
热议问题