Php: Want to learn PCRE Syntax
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:
[code:1]preg_match_all("/\(? (\d{3})? \)? (?(1) [\-\s] ) \d{3}-\d{4}/x",
"Call 555-1212 or 1-800-555-1212", $phones);[/code:1]
or
[code:1]if (ereg ("([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})", $date, $regs)) {
echo "$regs[3].$regs[2].$regs[1]";[/code:1]
or
[code:1]preg_match_all("|<[^>]+>(.*)</[^>]+>|U",
"<b>example: </b><div align=left>this is a test</div>",
$out, PREG_PATTERN_ORDER);[/code:1]
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?
|