Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

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']
Source by buggyprogrammer.com #
 
PREVIOUS NEXT
Tagged: #regex #list
ADD COMMENT
Topic
Name
3+1 =