You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

求助:如何用负向预查正则排除config.ini.php文件?

Fixing the Regex to Exclude .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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.08 11:38:14