fnmatch模块的使用此模块的主要作用是文件名称的匹配,并且匹配的模式使用的unix shell风格。 1.fnmatch
复制代码
2.fnmatchcase
print(fnmatch.fnmatchcase("text.py","text.*")) #True print(fnmatch.fnmatchcase("Text.py", "text.*")) # False print(fnmatch.fnmatchcase("Text.Py", "*.py")) # False print(fnmatch.fnmatchcase("Text.Py", "*.Py")) # True 3.filter
filelist=["a.text","b.jpg","c.png","d.py",'e.text',"sss.py"] print(fnmatch.filter(filelist,"?.py")) #匹配前面是一个字符的.py文件 输出:d.py 4.translate
(?s:[f,d,d,d,g,h]\.txt)\Z #\Z:匹配字符串结束,如果是存在换行,只匹配到换行前的结束字符串。#生成re匹配模块 #返回一个匹配对象 #<_sre.SRE_Match object; span=(0, 5), match='f.txt'> 本文作者:公众号python学习开发 本文链接:https://www.cnblogs.com/c-x-a/p/9261621.html 版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 2.5 中国大陆许可协议进行许可。 |
|