regex - RegEx 匹配超过 5 个斜杠的字符串
问题描述
我需要找到超过 5 个斜杠并忽略尾随斜杠的 URL。
喜欢比赛
https://www.url.com/cat1/cat2/cat3/cat4/
不匹配
https://www.url.com/cat1/cat2/cat3/
解决方案
这个做的工作:
^(?:[^/\r\n]*/){6,}[^/\r\n]+
解释:
^ : beginning of line
(?: : start non capture group
[^/\r\n]* : 0 or more any character that is not a slash or a linebreak
/ : 1 slash
){6,} : end group, must appear 6 or more times
[^/\r\n]+ : 1 or more any character that is not a slash or a linebreak
推荐阅读
- ios - How to get/post/update/delete data from a mongoDB database with an iOS app?
- python - Value not right while doing cumprod() to get cumulative returns in pandas
- dart - 空安全飞镖中的可选参数是否可以自动为空?如果不是,是否有一种简单的方法可以使我的代码为空安全?
- python - CondaHTTPError: HTTP 000 CONNECTION FAILED for url
- xml - 获取 XML 节点的属性值时出错
- c++ - How to solve Undefined symbols for architecture x86_64 error when using C++ API `llvm::InitializeAllAsmParsers()` in LLVM?
- python - How to fill 2d numpy array with some 2d numpy array
- node.js - I still get the MongooseServerSelectionError after allowing all access from anywhere when i connect with heroku
- azure - 如何让我的 AKS 群集向我的 ACR 进行身份验证?
- python-asyncio - 来自 aiohttp.ClientSession().post() 的带有多个图像文件的格式错误的请求