title: Python search for an exact string in a file
body: <pre><code>import re
  
  def find_string(file_name, word):
     with open(file_name, 'r') as a:
         for line in a:
             line = line.rstrip()
             if re.search("^{}$".format(word),line):
               return True
     return False
  
  if find_string('/tmp/myfile', 'hello'):
      print("found")
  else:
      print("not found")
  
  </code></pre>
  
  <p>myfile:</p>
  
  <pre><code>hello world #does not match
  hello #match
  </code></pre>
  
  <p>If I remove ^ and $ then it will match but it will also match "he","hel" etc. How can I match the exact string if there are multiples words on a single line?</p>