在 Python 中使用通配符匹配字符串的方法
目录
使用通配符匹配字符串:
- 使用
fnmatch.filter()
方法从列表中获取匹配模式的字符串。 - 使用
fnmatch.fnmatch()
方法检查字符串是否与模式匹配。
import fnmatch a_list = ['fql.txt', 'jiyik.txt', 'com.csv'] pattern = '*.txt' filtered_list = fnmatch.filter(a_list, pattern) print(filtered_list) #
- 上一篇 »Linux系统——特殊符号、通配符及正则表达式
- 下一篇 »linux的chown命令