可以说我有一个 list
list = ['this','is','just','a','test']
如何让用户进行通配符搜索?
搜索词:“th_s”
将返回“this”
最佳答案
正则表达式可能是解决此问题的最简单方法:
import re
regex = re.compile('th.s')
l = ['this', 'is', 'just', 'a', 'test']
matches = [string for string in l if re.match(regex, string)]