Created
July 25, 2012 22:17
-
-
Save shrink0r/3179049 to your computer and use it in GitHub Desktop.
Readable regex playing around with named groups.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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