[dev] regex gurus listen

Rich Lafferty rich@horde.org
Thu, 12 Jul 2001 13:14:10 -0400


On Thu, Jul 12, 2001 at 04:47:05PM +0000, Jan Schneider (janmailing@gmx.de) wrote:
> Hi regex gurus out there!
> 
> To make my vcard/ical-parser rfc2425-compliant I need a regex for a weird case. 
> 
> Take this line (remove linebreaks):
> ATTENDEE;PARTSTAT=DELEGATED;DELEGATED-
> TO="Mailto:E@example.com":Mailto:C@example.com
> 
> It has to be split at the first occuring colon _not_ in quoted
> string. In this case it has to be split at colon before the 2nd
> 'Mailto'.

Unless preg_* has adopted Perl's negative lookahead assertions (and
I'm pretty sure it hasn't), you can't do balanced parens/quotes/etc
with a regular expression. But it's easy to do the old way -- just
build a DFA that parses character by character.

  -Rich

-- 
Rich Lafferty --------------+-----------------------------------------------
 Montreal, Quebec, Canada   |  "Do not dangle the mouse by the cord or
 http://www.lafferty.ca/    |   throw it at coworkers."  -- SGI Indy manual
rich@lafferty.ca -----------+-----------------------------------------------