Php: Want to learn PCRE Syntax
Posted: Thu Jul 12, 2007 2:52 pm
I've been learning the php function which uses a Perl-compatible regular expression syntax like preg_match(), ereg() etc.
The function itself is not difficult to understand but when coming to the pattern syntax like Meta-characters, Pattern Modifiers quite make me headache.
See the example below:
or
or
Is there any resources other than the online php manual providing step by step level preferably with a lot of example to understand better about how to build this pattern from the scratch?
The function itself is not difficult to understand but when coming to the pattern syntax like Meta-characters, Pattern Modifiers quite make me headache.
See the example below:
Code: Select all
preg_match_all("/\(? (\d{3})? \)? (?(1) [\-\s] ) \d{3}-\d{4}/x",
"Call 555-1212 or 1-800-555-1212", $phones);Code: Select all
if (ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $date, $regs)) {
echo "$regs[3].$regs[2].$regs[1]";Code: Select all
preg_match_all("|<[^>]+>(.*)</[^>]+>|U",
"<b>example: </b><div align=left>this is a test</div>",
$out, PREG_PATTERN_ORDER);Is there any resources other than the online php manual providing step by step level preferably with a lot of example to understand better about how to build this pattern from the scratch?