title: Using re module in Python to substitute all punctuations in two strings to compare them?
body: <pre><code>import re
  def compare_strings(string1, string2):
    #Convert both strings to lowercase 
    #and remove leading and trailing blanks
    string1 = string1.lower().strip()
    string2 = string2.lower().strip()
  
    #Ignore punctuation
    punctuation = r&quot;[.?!,;:-']&quot;
    string1 = re.sub(punctuation, r&quot;&quot;, string1)
    string2 = re.sub(punctuation, r&quot;&quot;, string2)
  
    return string1 == string2
  
  print(compare_strings(&quot;Have a Great Day!&quot;, &quot;Have a great day?&quot;)) # Should be True
  print(compare_strings(&quot;It's raining again.&quot;, &quot;its raining, again&quot;)) # Should be True
  print(compare_strings(&quot;Learn to count: 1, 2, 3.&quot;, &quot;Learn to count: one, two, three.&quot;)) # Should be False
  print(compare_strings(&quot;They found some body.&quot;, &quot;They found somebody.&quot;)) # Should be False
  </code></pre>
  <p>The function above is removes trailing space, all punctuations from two strings and then it uses the .lower() function to remove nay capitalizations.</p>
  <p>The purpose of the function is to compare the content matter in two given strings and return True if they match or False if they don't match. There is a mistake in here which I cannot spot.</p>