title: Bash if statement with regex
body: <p>I try to use REGEX in bash in order to check if the parameter seems to be a valid path following this format:</p>
  
  <pre><code>/first/second
  </code></pre>
  
  <p>In java I use with success the following REGEX :</p>
  
  <pre><code>((\\/)[a-zA-Z0-9\\s_@\\-!#$%&amp;+=]+)+
  </code></pre>
  
  <p>But in bash I have some issue that I can't explain.
  In order to simplify my comprehension I try to use a simpler REGEX like that: </p>
  
  <pre><code>CHECKPATH="!/first/second"
  REGEX_PATH="((\/)[a-zA-Z0-9]+)+"
  if [[ ! ${CHECKPATH} =~ $REGEX_PATH ]]; then
      echo "error"
  else
      echo "OK"
  fi
  </code></pre>
  
  <p>I insert an "!" in the path just to check. So I should have "error" but not. With or without the "!" it changes nothing, what's the problem?</p>
  
  <p><strong>Update:</strong> (moved author's subquestion here from a comment)</p>
  
  <p>One more thing, if I use <code>^((\/)[a-zA-Z0-9\s_@#&amp;%!$+=\-]+)+$</code> it's ok, but it's not with <code>^((\/)[a-zA-Z0-9\s_@\-#&amp;%!$+=]+)+$</code>. I just changed the position of "\-" inside the regex, why?</p>