title: Check if string exists in a text file
body: <p>So I've got:</p>
  
  <pre><code>def CheckUserExists(user):
      with open("C:/~/database.txt", 'r') as file:
          if re.search(user, file.read()):
              return True
          else:
              return False
  
  username = input("Please enter you Username: ")
  if CheckUserExists(username) == True:
      print("You exist!")
  else:
      print("This user does not exist...")
  </code></pre>
  
  <p>However if you enter for example the letter 'a' and the is a user called 'brain'; the search picks up the a and returns True. How do I search for whole words?</p>
  
  <p>I have looked here: <a href="https://stackoverflow.com/questions/16432203/python-checking-if-string-is-in-a-text-file">How to check in Python if string is in a text file and print the line?</a> however I don't understand the piece of code:</p>
  
  <pre><code>re.search("\b{0}\b".format(w),line)
  </code></pre>