title: Regex - the difference in \\n and \n
body: <p>Sorry to add another "Regex explanation" question to the internet but I must know the reason for this. I have ran this regex through RegexBuddy and Regex101.com with no help.</p>
  
  <p>I came across the following regex (<code>"%4d%[^\\n]"</code>) while debugging a time parsing function. Every now and then I would receive an 'invalid date' error but only during the months of January and June. I mocked up some code to recreate exactly what was happening but I can't figure out why removing the one slash fixes it.</p>
  
  <pre><code>&lt;?php
  $format = '%Y/%b/%d';
  $random_date_strings = array(
      '2015/Jan/03',
      '1985/Feb/13',
      '2001/Mar/25',
      '1948/Apr/02',
      '1948/May/19',
      '2020/Jun/22',
      '1867/Jul/09',
      '1901/Aug/11',
      '1945/Sep/21',
      '2000/Oct/31',
      '2009/Nov/24',
      '2015/Dec/02'
      );
  
  $year = null;
  $rest_of_string = null;
  
  echo 'Bad Regex:';
  echo '&lt;br/&gt;&lt;br/&gt;';
  foreach ($random_date_strings as $date_string) {
      sscanf($date_string, "%4d%[^\\n]", $year, $rest_of_string);
      print_data($date_string, $year, $rest_of_string);
  }
  
  echo 'Good Regex:';
  echo '&lt;br/&gt;&lt;br/&gt;';
  foreach ($random_date_strings as $date_string) {
      sscanf($date_string, "%4d%[^\n]", $year, $rest_of_string);
      print_data($date_string, $year, $rest_of_string);
  }
  
  function print_data($d, $y, $r) {
  
      echo 'Date string: ' . $d;
      echo '&lt;br/&gt;';
      echo 'Year: ' . $y;
      echo '&lt;br/&gt;';
      echo 'Rest of string: ' . $r;
      echo '&lt;br/&gt;';
  }
  ?&gt;
  </code></pre>
  
  <p>Feel free to run this locally but the only two outputs I'm concerned about are the months of June and January. <code>"%4d%[^\\n]"</code> will truncate <code>$rest_of_string</code> to <code>/Ju</code> and <code>/Ja</code> while <code>"%4d%[^\n]"</code> displays the rest of the string as expected (<code>/Jan/03</code> &amp; <code>/Jun/22</code>).</p>
  
  <p>Here's my interpretation of the faulty regex:</p>
  
  <ul>
  <li><code>%4d%</code> - Get four digits.</li>
  <li><code>[^\\n]</code> - Look for those digits in between the beginning of the string and a new line.</li>
  </ul>
  
  <p>Can anyone please correct my explanation and/or tell me why removing the slash gives me the result I expect? </p>
  
  <p>I don't care for the HOW...I need the WHY.</p>