【发布时间】:2023-01-12 03:57:16
【问题描述】:
我可以制作一个对特定数量的字符返回 true 的正则表达式吗?
我需要的是一个规则来过滤 Google Analytics 上的一些 url,这些 slug 上总是有 5 个字符,删除任何查询字符串。
https://example.com/abcde -> true
https://example.com/abcde/ -> true
https://example.com/abcde?utm_source=google -> true
https://example.com/abcd -> false
https://example.com/abcdef -> false
我尝试使用 regex101.com 构建它但没有成功
【问题讨论】:
-
是的,你试过什么了吗?也许
/[^?]{5,}([?]?.*)$regex101.com/r/Bj5yjG/1 假设协议不包括在内 -
https?:\/\/.*\/[[:alpha:]]{5}([^[:alpha:]]|$)呢?