2013-07-04 87 views
1

如何在Python正则表达式下面的情况相匹配使用正则表达式的文件夹列表,比赛由蟒蛇

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

我需要从文件夹列表中匹配“ID87_070_138”这种类型的文件夹。

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

在此先感谢。

回答

1
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']