Skip to content

Instantly share code, notes, and snippets.

@elchappo
Created October 28, 2012 20:53
Show Gist options
  • Select an option

  • Save elchappo/3969871 to your computer and use it in GitHub Desktop.

Select an option

Save elchappo/3969871 to your computer and use it in GitHub Desktop.
PHP Regex checker
<?php
$string = "abcdefgh";
$regex = "/^[a-z]+$/i";
// Syntax is preg_match(regex, string, [, out_matches [, flags [, offset]]]);
if (preg_match($regex, $string)) {
printf("Pattern '%s' found in string '%s'\n", $regex, $string);
} else {
printf("No match found in string '%s'!\n", $string);
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment