📜  如何在列表中使用正则表达式 - Python 代码示例

📅  最后修改于: 2022-03-11 14:46:29.196000             🧑  作者: Mango

代码示例1
# list filtering with regex
import re
l = ['...', 'ram', 'karan','..','......', '....']

pattern = re.compile("\.\.+")
lst = [x for x in l if not re.match(pattern, x)]
print(lst)

# output 
['ram', 'karan']