title: Only allow some characters with grep?
body: <p>I would like to check a string, so it only contains the characters <code>0-9 a-z -</code>.</p>
  
  <p>When I do</p>
  
  <pre><code>regex='[-a-z0-9]*'
  string='abcd!'
  if [[ $string =~ $regex ]]
  then 
      echo "valid"
  else
      echo "not valid"
  fi
  </code></pre>
  
  <p>it outputs <code>valid</code>, where I would have expected <code>not valid</code> because <code>$string</code> contains a <code>!</code>.</p>