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

URL正则匹配失效求助:需精准匹配example.com下的特定路径

Solution to Exact URL Matching

The problem with your current regex is that it doesn't restrict where the regiony/regiuni pattern appears in the URL—it will match any occurrence of those substrings anywhere in the path, which is why it's catching longer URLs like /obshestvo/regiony-zastavili-ego-zhiti.

To fix this, you need to anchor your regex to match the entire URL path after the domain, ensuring there are no extra segments before or after your target patterns. Here's the corrected regex:

^http://example.com/(regiony|regioni)\/?$

Breakdown of the regex:

  • ^: Anchors the match to the start of the string, ensuring the URL begins exactly with http://example.com/.
  • (regiony|regioni): Matches either of your target path segments (swap regioni with regiuni here if that's the actual pattern you need—your question mentions both, so adjust accordingly).
  • \/?: Makes the trailing slash optional (matches both with and without the slash at the end).
  • $: Anchors the match to the end of the string, ensuring there's nothing after the target segment (no extra path parts, query parameters, etc.).

Testing against your URL list:

  • ✅ Matches:
    • http://example.com/regiony/
    • http://example.com/regioni/
    • http://example.com/regiony
    • http://example.com/regioni
  • ❌ Doesn't match:
    • http://example.com/ru/regiony/ (has an extra /ru/ segment before the target)
    • http://example.com/regiuni/ (only if you kept regioni in the regex—swap to regiuni if this should be a match)
    • https://example.com/obshestvo/regiony-zastavili-ego-zhiti (extra path segments and HTTPS instead of HTTP)
    • http://example.com/obshestvo/regiony (extra /obshestvo/ segment before the target)

If you need to support HTTPS as well, you can modify the regex to include an optional s:

^https?://example.com/(regiony|regioni)\/?$

Content of the question originates from Stack Exchange, question author Jadasdas

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.05.26 11:00:23