Skip to content

Instantly share code, notes, and snippets.

@shrink0r
Created July 25, 2012 22:17
Show Gist options
  • Save shrink0r/3179049 to your computer and use it in GitHub Desktop.
Save shrink0r/3179049 to your computer and use it in GitHub Desktop.
Readable regex playing around with named groups.
<?php
$pattern = <<<EOT
/
(?(DEFINE)
(?<T_NUM> [0-9] )
)
^(?&T_NUM)$
/x
EOT;
$text = '1';
if (preg_match($pattern, $text))
{
echo "matched!\n";
}
else
{
echo "no match!\n";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment