title: Right way to escape backslash [ \ ] in PHP regex?
body: <p>Just out of curiosity, I'm trying to figure out which exactly is the right way to escape a backslash for use in a PHP regular expression pattern like so:</p>
  
  <p><strong>TEST 01: (3 backslashes)</strong></p>
  
  <pre><code>$pattern = "/^[\\\]{1,}$/";
  $string = '\\';
  
  // ----- RETURNS A MATCH -----
  </code></pre>
  
  <p><strong>TEST 02: (4 backslashes)</strong></p>
  
  <pre><code>$pattern = "/^[\\\\]{1,}$/";
  $string = '\\';
  
  // ----- ALSO RETURNS A MATCH -----
  </code></pre>
  
  <p>According to the articles below, 4 is supposedly the right way but what confuses me is that both tests returned a match. If both are right, then is 4 the preferred way?</p>
  
  <p><strong>RESOURCES:</strong></p>
  
  <ul>
  <li><a href="http://www.developwebsites.net/match-backslash-preg_match-php/" rel="noreferrer">http://www.developwebsites.net/match-backslash-preg_match-php/</a></li>
  <li><a href="https://stackoverflow.com/questions/4025482/cant-escape-the-backslash-with-regex">Can&#39;t escape the backslash with regex?</a></li>
  </ul>