Python: regex elements match with List -


i have list, want compare each element of list against list of regex , print not found regex.regex coming config file:

exclude_reg_list= qa*,bar.*,qu*x

code:

import re read_config1 = open("config.ini", "r") line1 in read_config1:     if re.match("exclude_reg_list", line1):          exc_reg_list = re.split("= |,", line1)          l = exc_reg_list.pop(0)          item in exc_reg_list:              print item 

i able print regexs 1 one, how compare regexs against list.

instead of using re module, going use fnmatch module since looks wildcard pattern matching.

please check link more information on fnmatch.

extending code desired output :

import fnmatch exc_reg_list = []  #list of words checking check_word_list = ["qart","bar.txt","quit","quest","qudx"]  read_config1 = open("config.ini", "r") line1 in read_config1:     if re.match("exclude_reg_list", line1):         exc_reg_list = re.split("= |,", line1)          #exclude_reg_list= qa*,bar.*,qu*x         word in check_word_list:             found = 0             regex in exc_reg_list:                if fnmatch.fnmatch(word,regex):                     found = 1             if found == 0:                    print word  

output:

c:\users>python main.py quit quest 

please let me know if helpful.


Comments