简体   繁体   English

在python中找到文件名中的模式

[英]Find the pattern inside the file name in python

I have the database with the specific names.我有具有特定名称的数据库。 I need to iterate the database records and find the records which have the appropriate pattern.我需要迭代数据库记录并找到具有适当模式的记录。 For example: Pattern with wildcard: abc.*.cde File name: abc.123.cde例如:带通配符的模式: abc.*.cde文件名: abc.123.cde

How can I check that the name "abc.123.cde" is a part of the pattern "abc.*.cde" ?如何检查名称 "abc.123.cde" 是否是模式 "abc.*.cde" 的一部分?

Seems I have to use the fnmatch module:似乎我必须使用 fnmatch 模块:

fnmatch.fnmatch(files, 'abc.*.cde')

Will return me the files according to the pattern.将根据模式将文件归还给我。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM