如何使用通配符的字符串匹配
问题描述:
我怎样才能做到这一点:如何使用通配符的字符串匹配
if 'class="*word*"' in html:
print "True."
else:
print "False."
在Linux中使用*作为通配符字符是怎样的?
答
如果你只是想匹配的Unix文件名模式匹配,可以使用专用模块fnmatch:如果你想要做的先进模式
import fnmatch
words = ["testing", "wildcard", "in", "python"]
filtered = fnmatch.filter(words, 'p?thon')
# filtered = ['python']
filtered = fnmatch.filter(words, 'w*')
# filtered = ['wildcard']
匹配,使用正则表达式。
如果你遵循这条线索,你会意识到[你不应该这样解析HTML](https://stackoverflow.com/q/1732348/102441) – Eric