Answers for "python list find all regex"

0

array search with regex python

import re

mylist = ["dog", "cat", "wildcat", "thundercat", "cow", "hooo"]
r = re.compile(".*cat")
newlist = list(filter(r.match, mylist)) # Read Note
print(newlist)
Posted by: Guest on June-13-2020
0

regex findall

import re
# regex for finding mentions in a tweet
regex = r"(?<!RTs)@S+"
tweet = '@tony I am so over @got and @sarah is dead to me.'

# mentions = ['@tony', '@got', '@sarah'] 
mentions = re.findall(regex, tweet)
Posted by: Guest on December-16-2020

Python Answers by Framework

Browse Popular Code Answers by Language