You are here: Recursive regular expression (or alternative) « PHP Programming Language « IT news, forums, messages
Recursive regular expression (or alternative)

Posted by Andrι Hδnsel on 04/12/06 23:04

Hi,

I'm looking for a pattern to parse the following subject:

blabla(cond1)?{abc}:{def}blabla(cond2)?{qwe(cond3)?{poi}:{iop}}

Probably I can't do that by executing a regexp _once_, so I need some
kind of recursive call to get those two lists (e.g. in an array):
array(
0 => array("cond1","abc","def"),
1 => array("cond2","qwe(cond3)?{poi}:{iop}","")
)
and for the second one then I need the array:
array(
0 => array("cond3","poi","iop")
)

Or in words: In a configuration file I have _nested_ conditional blocks
in the format (condition)?{content_when_true}:{content_when_false}
while the false content ist optional.

I built the following pattern, but thats just a bad guess:
/\(([a-zA-Z0-9_ &|]+)\)\?\{(.*)\}(\:\{(.*)\})?/
It matches both blocks when it's greedy and ignores the nested block
when it's ungreedy.

If you have any completly different solution I'll be glad to hear it,
too. :)

Best regards,
AndrΓ©

 

Navigation:

[Reply to this message]


УдалСнная Ρ€Π°Π±ΠΎΡ‚Π° для программистов  •  Как Π·Π°Ρ€Π°Π±ΠΎΡ‚Π°Ρ‚ΡŒ Π½Π° Google AdSense  •  England, UK  •  ΡΡ‚Π°Ρ‚ΡŒΠΈ Π½Π° английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Π‘Π°ΠΉΡ‚ ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ Π² Π‘Ρ‚ΡƒΠ΄ΠΈΠΈ Π’Π°Π»Π΅Π½Ρ‚ΠΈΠ½Π° ΠŸΠ΅Ρ‚Ρ€ΡƒΡ‡Π΅ΠΊΠ°
ΠΈΠ·Π³ΠΎΡ‚ΠΎΠ²Π»Π΅Π½ΠΈΠ΅ ΠΈ ΠΏΠΎΠ΄Π΄Π΅Ρ€ΠΆΠΊΠ° Π²Π΅Π±-сайтов, Ρ€Π°Π·Ρ€Π°Π±ΠΎΡ‚ΠΊΠ° ΠΏΡ€ΠΎΠ³Ρ€Π°ΠΌΠΌΠ½ΠΎΠ³ΠΎ обСспСчСния, поисковая оптимизация