title: regex differentiating between ISBN-10 and ISBN-13
body: <p>I have an If-else statement which checks a string to see whether there is an ISBN-10 or ISBN-13 (book ID). </p>
  
  <p>The problem I am facing is with the ISBN-10 check which occurs before the ISBN-13 check, the ISBN-10 check will match anything with 10 characters or more and so may mistake an ISBN-13 for an ISBN-10.</p>
  
  <p>here is the code...</p>
  
  <pre><code>$str = "ISBN:9780113411436";
  
  if(preg_match("/\d{9}(?:\d|X)/", $str, $matches)){
     echo "ISBN-10 FOUND\n";  
     //isbn returned will be 9780113411
     return 0;
  }
  
  else if(preg_match("/\d{12}(?:\d|X)/", $str, $matches)){
     echo "ISBN-13 FOUND\n";
     //isbn returned will be 9780113411436
     return 1;
  }
  </code></pre>
  
  <p>How do I make sure I avoid this problem?</p>