[英]Python Regex match character before or after slash
我想编写一个基于以下内容匹配字符串的正则表达式:
/
之前和之后不应有空格/
之前或之后只能有两个特殊字符 ( *
, :
)/
并且只要没有空格就应该被视为单个匹配项示例输入看起来像
Artifacts path 'artifacts_tube/AtomInstall*/**' not found. // 1 match
</root> // 0 matches
Failed steps: [<DF2 [D:/Users/work/tmp/assets/dummyfailer]>] // 1 match
Options : *.* /NS /NC /NDL /COPY:DAT /NP /MT:32 /R:11 /W:30 // 0 matches
Copy Dir: D:/Users/tempdir/tmp8fo -> D:/Users/tempdir/tmpj7xj // 2 matches
我有一个简单的正则表达式,但它不符合上述所有标准\S*\/\S*
。 Output 用于我的正则表达式
Artifacts path 'artifacts_tube/AtomInstall*/**' not found. // 1 match
</root> // 1 match
Failed steps: [<DF2 [D:/Users/work/tmp/assets/dummyfailer]>] // 1 match
Options : *.* /NS /NC /NDL /COPY:DAT /NP /MT:32 /R:11 /W:30 // 8 matches
Copy Dir: D:/Users/tempdir/tmp8fo -> D:/Users/tempdir/tmpj7xj // 2 matches
这并不完全符合您的要求(它允许:
和*
出现在路径中的任何位置),但我认为您可以通过它实现您的目标。
(?!\/[^:*])(?![^:*]\/)[\w\/*:]*\/[\w\/*:]*
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.