Answers for "python regex from list of string that contains substring"

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 regex from list of string that contains substring"

Python Answers by Framework

Browse Popular Code Answers by Language