我想使用正则表达式来匹配macOS上的此文件路径:
/Users/username/Library/Containers/com.tencent.xinWeChat/...
此路径中有许多子文件夹级别,但是我想排除此特定路径。
/Users/username/Library/Containers/com.tencent.xinWeChat/Data/Library/Application Support/com.tencent.xinWeChat/2.0b4.0.9/8be628ba3eab5f8c52f6f1b22f897153/Message/MessageTemp/8be628ba3eab5f8c52f6f1b22f897153/OpenData/...
我想在正则表达式中排除包含“ OpenData”的路径,因此我使用了这个:
R"^/Users/[^/]+/Library/Containers/com\.tencent\.\w+/.+/(?!OpenData)/.+"
但这是行不通的。负向前进对我来说有点难。有人可以告诉我正确的正则表达式吗?谢谢!
您可以使用
^/Users/[^/]+/Library/Containers/com\.tencent\.\w+/(?!(?:.*/)?OpenData(?:/|$)).+
细节
^
-字符串开始/Users/
-文字子字符串[^/]+
-1个以上字符 /
/Library/Containers/com\.tencent\.
-一个/Library/Containers/com.tencent.
字符串\w+
-1个以上的字符/
-一个/
字符(?!(?:.*/)?OpenData(?:/|$))
-如果OpenData
网址中包含子部分,则匹配失败的否定超前行为.+
-除换行符以外的任意1个以上的字符。本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句