Python正则表达式在斜杠之前或之后匹配字符

2024-10-02 12:37:27 发布

您现在位置:Python中文网/ 问答频道 /正文

我想编写一个正则表达式,它根据以下内容匹配字符串:

  • 字符串在/前后不应有空格
  • 字符串在/之前或之后只能有两个特殊字符(*:
  • 字符串可以有任意数量的/,只要没有空格,就可以将其视为单个匹配项

示例输入看起来像

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*。我的正则表达式的输出

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


Tags: path字符串matchnotrootusers空格matches

热门问题