title: How to print matching strings in python with regex?
body: <p>I am working on a Python script that would go through a directory with a bunch of files and extract the strings that match a certain pattern.
  More specifically, I'm trying to extract the values of serial number and a max-limit, and the lines look something like this:</p>
  <pre><code>#serial number = 642E0523D775
  
  max-limit=50M/50M
  </code></pre>
  <p>I've got the script to go through the files, but I'm having an issue with it actually printing the values that I want it to. Instead of it printing the values, I just get the 'Nothing fount' output.</p>
  <p>I'm thinking that it probably has something to do with the regex I'm using, but I can't for the life of me figure out how formulate this.</p>
  <p>The script I've come up with so far:</p>
  <pre><code>import os
  import re
  
  #Where I'm searching
  
  user_input = &quot;/path/to/files/&quot;
  directory = os.listdir(user_input)
  
  #What I'm looking for
  
  searchstring = ['serial number', 'max-limit']
  re_first = re.compile ('serial.\w.*')
  re_second = re.compile ('max-limit=\w*.\w*')
  
  #Regex combine
  regex_list = [re_first, re_second]
  
  #Looking
  
  for fname in directory:
      if os.path.isfile(user_input + os.sep + fname):
          # Full path
          f = open(user_input + os.sep + fname, 'r')
          f_contents = f.read()
          content = fname + f_contents
          files = os.listdir(user_input)
          lines_seen = set()
  
          for f in files:
           print(f)
           if f not in lines_seen:  # not a duplicate
  
            for regex in regex_list:
                matches = re.findall(regex, content)
  
                if matches != None:
                  for match in matches:
                    print(match)
                else:
                    print('Nema')
          f.close()
  </code></pre>