python regex from list of string that contains substring

Solutions on MaxInterview for python regex from list of string that contains substring by the best coders in the world

showing results for - "python regex from list of string that contains substring"
Conor
04 Jan 2019
1# Python3 program to Filter list of 
2# strings based on another list
3import re
4  
5def Filter(string, substr):
6    return [str for str in string 
7    if re.match(r'[^\d]+|^', str).group(0) in substr]
8      
9# Driver code
10string = ['city1', 'class5', 'room2', 'city2']
11substr = ['class', 'city']
12print(Filter(string, substr))
13