how to use regex in a list

Solutions on MaxInterview for how to use regex in a list by the best coders in the world

showing results for - "how to use regex in a list"
Niklas
23 Aug 2016
1# list filtering with regex
2import re
3l = ['...', 'ram', 'karan','..','......', '....']
4
5pattern = re.compile("\.\.+")
6lst = [x for x in l if not re.match(pattern, x)]
7print(lst)
8
9# output 
10['ram', 'karan']