在python中使用regex匹配文件夹列表

2024-04-18 22:18:54 发布

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

如何在python regex中匹配以下大小写

str = "https://10.0.4.3/myrepos/Projects/ID87_070_138"

我需要从文件夹列表中匹配“ID87\u 070\u 138”这类文件夹。你知道吗

The pattern is "ID<number>_<number>_<Number>".

提前谢谢。你知道吗


Tags: thehttps文件夹idnumber列表isregex
1条回答
网友
1楼 · 发布于 2024-04-18 22:18:54
ID\d+_\d+_\d+

匹配ID,后跟三组一个多个数字,用下划线分隔。你知道吗

以及Python代码:

> import re
> str = "https://10.0.4.3/myrepos/Projects/ID87_070_138"
> print re.findall(r"ID\d+_\d+_\d+", str)

结果是:

['ID87_070_138']

相关问题 更多 >