Answers for "how to write regular expression for list in python"

1

how to use regex in a list

# 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']
Posted by: Guest on June-14-2021

Code answers related to "how to write regular expression for list in python"

Python Answers by Framework

Browse Popular Code Answers by Language