topical media & game development

talk show tell print

basic-regex-23-NegatedCharacterClass.php / php



  <html>
  <head>
  <title>Negated Character Class Example</title>
  </head>
  <body>
  <?php
  sequenceToMatch1 = "12345";
  sequenceToMatch2 = "123 45";
  negCharClass = "/[^0-9]/";
  nonNumMatch = preg_match(negCharClass, sequenceToMatch1);
  if (nonNumMatch)
  {
  echo "<p>There was a non-numeric character in sequenceToMatch1.</p>";
  }
  else
  {
  echo "<p>All characters were numeric in sequenceToMatch1.</p>";
  }
  nonNumMatch = preg_match(negCharClass, sequenceToMatch2);
  if (nonNumMatch)
  {
  echo "<p>A non-numeric character was found in sequenceToMatch2.</p>";
  }
  else
  {
  echo "<p>All characters were numeric in sequenceToMatch2.</p>";
  }
  ?>
  </body>
  </html>


(C) Æliens 20/2/2008

You may not copy or print any of this material without explicit permission of the author or the publisher. In case of other copyright issues, contact the author.