regex - python re.match list of regular expressions -


i have 2 lists: ignorelist list of regular expressions, , list calledurllist. trying make if index item in urllist matches regular expression in ignorelist, not added finallist

ignorelist = ['(?:\.)amazon\.com(?:\/(?:.*))',             '(?:\.)google\.com(?:\/(?:.*))']  urllist = ['api.amazon.com/', 'fakedomain.com/'] finallist = []  r in ignorelist:     r = re.compile(r)     finallist = [x x in urllist if not r.match(x)] 

which outputs

['api.amazon.com/', 'fakedomain.com/'] 

i'm trying make output ['fakedomain.com/'] because wouldn't match regular expressions in ignorelist

several issues here:

  • re.match searches @ start of line. expressions not built that. use re.search.
  • your assigning result in loop: wrong logic.

i do:

import re  ignorelist = ['(?:\.)amazon\.com(?:\/(?:.*))',             '(?:\.)google\.com(?:\/(?:.*))']  urllist = ['api.amazon.com/', 'fakedomain.com/']   finallist = [x x in urllist if not any(re.search(r,x) r in ignorelist)] 

so finallist contains urls not matching of regexes of ignorelist

result:

['fakedomain.com/'] 

note didn't "compile" regexes, may gain speed doing when testing lot of domains.


Comments

Popular posts from this blog

What is happening when Matlab is starting a "parallel pool"? -

angular - DownloadURL return null in below code -

php - Cannot override Laravel Spark authentication with own implementation -