title: Is there anyway to use variable in search function of Regex?
body: <p>I wonder if there is any way to use a special variable in regex and mix it with regex code??
  this is a function that takes type and folder and searches all files and folders in it to find all files with that type. and the error occurred in line 10 when I tried to combine them.</p>
  <pre><code>def explore(extension,path):
      import os
      import re
      d = dict()
      for dirpath, dirs, files in os.walk(path):
          count = 0
          for filename in files:
              fname = os.path.join(dirpath,filename)
              fname = fname.lower()
              j = &quot;.\&quot;+extension+&quot;$&quot;
              if re.search(j,fname) != None:
                  if fname.endswith(extension):
                      count+=1
                      d[dirpath]=count
      print(d)
  </code></pre>