title: Python: How to use RegEx in an if statement?
body: <p>I have the following code which looks through the files in one directory and copies files that contain a certain string into another directory, but I am trying to use Regular Expressions as  the string could be upper and lowercase or a mix of both. </p>
  
  <p>Here is the code that works, before I tried to use RegEx's</p>
  
  <pre><code>import os
  import re
  import shutil
  
  def test():
      os.chdir("C:/Users/David/Desktop/Test/MyFiles")
      files = os.listdir(".")
      os.mkdir("C:/Users/David/Desktop/Test/MyFiles2")
      for x in (files):
          inputFile = open((x), "r")
          content = inputFile.read()
          inputFile.close()
          if ("Hello World" in content)
              shutil.copy(x, "C:/Users/David/Desktop/Test/MyFiles2")
  </code></pre>
  
  <p>Here is my code when I have tried to use RegEx's</p>
  
  <pre><code>import os
  import re
  import shutil
  
  def test2():
      os.chdir("C:/Users/David/Desktop/Test/MyFiles")
      files = os.listdir(".")
      os.mkdir("C:/Users/David/Desktop/Test/MyFiles2")
      regex_txt = "facebook.com"
      for x in (files):
          inputFile = open((x), "r")
          content = inputFile.read()
          inputFile.close()
          regex = re.compile(regex_txt, re.IGNORECASE)
  </code></pre>
  
  <p>Im guessing that I need a line of code that is something like</p>
  
  <pre><code>if regex = re.compile(regex_txt, re.IGNORECASE) == True
  </code></pre>
  
  <p>But I cant seem to get anything to work, if someone could point me in the right direction it would be appreciated. </p>