title: Check if a string contains only characters from a regular expression
body: <p>Trying to create a function which with a given a <strong>regular expression which holds all the legal characters</strong>, a string will be checked if it <strong>only</strong> contains those characters.</p>
  
  <p>For example</p>
  
  <pre><code>import re
  legal_characters = r'[\*\-]' # Matches asterisc and dash characters
  
  def is_legal(test_string):
      if re.match(legal_characters, test_string):
          print("Legal")
      else:
          print("Not legal")
  
  is_legal("***---123")  # should print "Not legal"
  is_legal("AbC123")     # should print "Not legal"
  is_legal("*-*-*")      # should print "Legal"
  </code></pre>
  
  <p>output:</p>
  
  <pre><code>Not legal
  Not legal
  Not legal
  </code></pre>
  
  <p>I do not really understand why. Could someone please explain?</p>