訂閱裡有一百多個節點,手寫分組名單不現實,而且訂閱一更新就失效。
Mihomo 的 include-all + filter 能讓分組自動收編匹配的節點——寫對正則是關鍵。
基本用法
proxy-groups:
- name: "🇭🇰 香港"
type: url-test
include-all: true # 纳入所有节点
filter: "(?i)香港|HK|Hong ?Kong" # 只保留匹配的
exclude-filter: "(?i)剩余|到期|官网" # 再排除掉这些
url: http://www.gstatic.com/generate_204
interval: 300
tolerance: 50執行順序:先 include-all 收集全部 → 再 filter 保留匹配 → 最後 exclude-filter 剔除。
三個 include 選項的區別
| 選項 | 納入範圍 |
|---|---|
include-all: true | proxies 段 + 所有 proxy-provider |
include-all-proxies: true | 只有 proxies 段裡手寫的節點 |
include-all-providers: true | 只有 provider 裡的節點 |
use: [provider名] | 指定的 provider |
自建節點寫在 proxies 裡、訂閱節點走 provider 時,這幾個選項能幫你精確控制哪些節點進哪個組。
正則基礎(夠用就行)
按地區分組
最常見的需求。各地區的常見叫法都要覆蓋:
# 香港
filter: "(?i)香港|港|HK|Hong ?Kong|HKG|🇭🇰"
# 台灣
filter: "(?i)台湾|台|TW|Taiwan|TPE|🇹🇼"
# 日本
filter: "(?i)日本|日|JP|Japan|东京|大阪|Tokyo|Osaka|🇯🇵"
# 新加坡
filter: "(?i)新加坡|狮城|SG|Singapore|🇸🇬"
# 美国
filter: "(?i)美国|美|US|USA|United ?States|洛杉矶|圣何塞|西雅图|🇺🇸"
# 韓国
filter: "(?i)韩国|韩|KR|Korea|首尔|Seoul|🇰🇷"
# 英国
filter: "(?i)英国|UK|United ?Kingdom|London|伦敦|🇬🇧"按倍率篩選
很多訂閱在節點名裡標了倍率(0.5x、1x、3x)。
# 只要低倍率(省流量)
filter: "(?i)0\\.[0-9]x|1x|1\\.0x"
# 排除高倍率
exclude-filter: "(?i)[2-9](\\.[0-9])?x|1[0-9]x"
# 只要標了「專線」「IPLC」「IEPL」的(通常品質最好)
filter: "(?i)IPLC|IEPL|专线|内网|高级|premium"排除偽節點
訂閱裡那些「剩餘流量:128 GB」「距離到期:30 天」的條目,本質上是把資訊塞進節點名裡顯示,它們並不是真節點。
exclude-filter: "(?i)剩余|到期|过期|流量|重置|官网|订阅|网址|群组|发布|防失联|测试|Traffic|Expire|GB|Days?"按協議篩選
# 只要 Hysteria2(低延遲場景)
filter: "(?i)hy2|hysteria"
# 排除某些協議(Mihomo 提供了專門的欄位,更可靠)
exclude-type: "ss|ssr|http"exclude-type 按實际協議類型過濾,比在節點名裡猜協議靠譜得多。
組合條件
正則本身不好表達「且」,但可以用兩層過濾實現:
# 香港 且 低倍率
- name: "🇭🇰 香港低倍率"
type: url-test
include-all: true
filter: "(?i)香港|HK"
exclude-filter: "(?i)[2-9](\\.[0-9])?x|剩余|到期"
interval: 300先用 filter 圈定香港,再用 exclude-filter 排掉高倍率和偽節點。
需要更複雜的「且」邏輯,可以用正則的前瞻斷言:
# 同時包含「香港」和「IPLC」
filter: "(?i)(?=.*香港)(?=.*IPLC).*"能不用就不用——可讀性太差,後期維護困難。
一套完整模板
proxy-providers:
main:
type: http
url: "你的订阅链接"
interval: 3600
path: ./providers/main.yaml
header: { User-Agent: ["clash.meta"] }
exclude-filter: "(?i)剩余|到期|过期|流量|重置|官网|订阅|群组|发布|防失联"
health-check: { enable: true, url: http://www.gstatic.com/generate_204, interval: 300, lazy: true }
proxy-groups:
# 總開關
- name: "🚀 节点选择"
type: select
proxies: ["♻️ 自动选择", "🇭🇰 香港", "🇯🇵 日本", "🇸🇬 新加坡", "🇺🇸 美国", "🇨🇳 台湾", "💎 专线", DIRECT]
# 全局自動
- name: "♻️ 自动选择"
type: url-test
use: [main]
url: http://www.gstatic.com/generate_204
interval: 300
tolerance: 50
lazy: true
# 地區組
- name: "🇭🇰 香港"
type: url-test
use: [main]
filter: "(?i)香港|HK|Hong ?Kong|🇭🇰"
interval: 300
tolerance: 50
- name: "🇯🇵 日本"
type: url-test
use: [main]
filter: "(?i)日本|JP|Japan|东京|大阪|🇯🇵"
interval: 300
tolerance: 50
- name: "🇸🇬 新加坡"
type: url-test
use: [main]
filter: "(?i)新加坡|狮城|SG|Singapore|🇸🇬"
interval: 300
tolerance: 50
- name: "🇺🇸 美国"
type: url-test
use: [main]
filter: "(?i)美国|US|USA|United ?States|洛杉矶|圣何塞|🇺🇸"
interval: 300
tolerance: 50
- name: "🇨🇳 台湾"
type: url-test
use: [main]
filter: "(?i)台湾|TW|Taiwan|台北|🇹🇼"
interval: 300
tolerance: 50
# 專線組(品質最好的,給游戲和影片用)
- name: "💎 专线"
type: fallback
use: [main]
filter: "(?i)IPLC|IEPL|专线|内网"
interval: 600
# 按用途
- name: "🤖 AI 服务"
type: select
proxies: ["🇺🇸 美国", "🇯🇵 日本", "🇸🇬 新加坡", "🚀 节点选择"]
- name: "🎬 流媒体"
type: select
proxies: ["🇭🇰 香港", "🇸🇬 新加坡", "💎 专线", "🚀 节点选择"]
- name: "🎮 游戏"
type: select
proxies: ["💎 专线", "🇭🇰 香港", "🇯🇵 日本"]
- name: "🐟 漏网之鱼"
type: select
proxies: ["🚀 节点选择", DIRECT]怎麼驗證 filter 寫對了
組是空的,按順序查:
- 正則裡有沒有拼寫錯誤(中文節點名注意有沒有多餘空格)
- 是不是漏了
(?i),而節點名是小寫的hk exclude-filter是不是太寬,把要的也排掉了use指向的 provider 載入成功了嗎
混進了不該有的節點:
在 exclude-filter 裡加上那個節點名的特徵詞,或者把 filter 寫得更精確(加 ^ 或 $ 限定位置)。
常見陷阱
不用 filter 的場景
節點數量少(十幾個以內)、名字不規範、或者你想完全掌控每個組裡有什麼,直接手寫節點名也沒問題:
- name: "🇭🇰 香港"
type: url-test
proxies:
- "香港 IPLC 01"
- "香港 BGP 02"
interval: 300代價是訂閱更新後新增的節點不會自動進來,需要手動維護。
小結
(?i)幾乎每次都要加- 單個漢字不要單獨當過濾詞,會誤傷
- 偽節點在 provider 層面統一排除,比每個組寫一遍省事
exclude-type比在名字裡猜協議可靠- 寫完一定要在代理頁面數一下節點數量驗證
- 專線單獨成組用 fallback,給游戲和影片用
相關文件
十幾種規則類型的語法、匹配邏輯與效能開銷對照表,講清楚 no-resolve 的作用、規則順序為什麼決定一切,以及怎麼用連接頁反查命中了哪條規則。
用外部規則集替代幾百條手寫規則。講清楚 domain/ipcidr/classical 三種 behavior 的差異、text 與 yaml 格式、更新間隔怎麼設,以及規則集不生效時怎麼查。