求助:如何用负向预查正则排除config.ini.php文件?
.ini.php Files in XL-Deploy Hey there! Let's work through why your regex isn't excluding config.ini.php files and get you a reliable solution.
The Issue with Your Current Attempt
Your regex .+.(?!ini\.php).* fails because the negative lookahead (?!ini\.php) only checks if the immediate characters right after the last dot are ini.php. For config.ini.php, the last dot is followed by php—not ini.php—so the lookahead passes, and the file gets matched. That's not the behavior you want!
The Correct Regex
You need to check if the entire filename ends with .ini.php and exclude those cases. Here's a robust solution:
^(?!.*\.ini\.php$).+\..+$
Let's break this down step by step:
^Anchors the match to the start of the filename.(?!.*\.ini\.php$)A negative lookahead that ensures the filename does not end with.ini.php.\.Ensures the filename has at least one literal dot (aligning with your goal of targeting files with extensions).$Anchors the match to the end of the filename.
What It Matches/Excludes
- ✅ Matches:
foo.bar,index.php,test.config,app.txt - ❌ Excludes:
config.ini.php(and any other file ending with.ini.php)
Alternative (Using Negative Lookbehind)
If your regex engine supports lookbehinds (most modern ones like Python, Java, or JavaScript do), you can use this more concise version:
^.+?(?<!\.ini\.php)$
This uses a negative lookbehind (?<!\.ini\.php) to verify the filename doesn't end with .ini.php.
Quick Note on Your Original Regex
Just a small heads-up: Your original .+.(?!php).* has an unescaped dot (.), which matches any character—not just a literal dot. If you want to properly target files with extensions, you should escape it to \., like .+\.(?!php).* (though this still wouldn't solve the .ini.php exclusion problem on its own).
内容的提问来源于stack exchange,提问作者William Rudent

