Re: Reg-ex help
| From: | Jim Lucas | Date: | Thu, 05 Feb 2009 06:15:36 +0000 |
| Subject: | Re: Reg-ex help | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-287680@lists.php.net to get a copy of this message | ||
Craige Leeder wrote:
Hey guys, I'm trying to write a regular expression to match a tag for my frameworks template engine. I seem to be having some trouble. The expression should match: {:seg 'segname':} {:seg 'segname' cache:} What I have is... $fSegRegEx = "#\{:seg \'[a-z0-9\-\_]{3,}\'( cache)?:\}#i"; Which when run against my test data, seems to match: "{:seg 'segname' cache:}" " cache" Thanks guys. This has been bugging me for a couple days. - CraigeI used some of your code, but try this variant on for size. <plaintext> <?php error_reporting(E_ALL); ini_set('display_errors', 1); $dummyData = <<<DATA <html> <body> <h1>{:seg 'title':}</h1> <h1>{:seg 'title' cache:}</h1> </body> </html> DATA; # For arguments sake, I'll provide the whole code snippet... $fSegRegEx = "|\{:(seg) \'([a-z0-9\-\_]{3,})\'\s?(cache)?:\}|i"; preg_match_all($fSegRegEx, $dummyData, $faSegMatches, PREG_SET_ORDER); print_r($faSegMatches); ?> Not sure what your input is going to be (HTML, XML, etc...) so I used HTML Anyways, output from the above code is this: <plaintext> Array (
[0] => Array
(
[0] => {:seg 'title':}
[1] => seg
[2] => title
)
[1] => Array
(
[0] => {:seg 'title' cache:}
[1] => seg
[2] => title
[3] => cache
)
)
Hope this starts you down the right path.
--
Jim Lucas
"Some men are born to greatness, some achieve greatness,
and some have greatness thrust upon them."
Twelfth Night, Act II, Scene V
by William Shakespeare