Answers for "python test if a string contains one of a list of substring with "re""

2

python list contains substring

str_list = ["one", "two", "three"]
substr = "wo"
if any(substr in str for str in str_list):
	print('Yes!')
Posted by: Guest on September-01-2021
0

python regex from list of string that contains substring

# Python3 program to Filter list of 
# strings based on another list
import re
  
def Filter(string, substr):
    return [str for str in string 
    if re.match(r'[^\d]+|^', str).group(0) in substr]
      
# Driver code
string = ['city1', 'class5', 'room2', 'city2']
substr = ['class', 'city']
print(Filter(string, substr))
Posted by: Guest on April-27-2021

Code answers related to "python test if a string contains one of a list of substring with "re""

Python Answers by Framework

Browse Popular Code Answers by Language