Re: [pcre-dev] trying to write PCRE-compatible regular expre…

Top Page
Delete this message
Author: Philip Hazel
Date:  
To: Oleg Sychev
CC: pcre-dev
Subject: Re: [pcre-dev] trying to write PCRE-compatible regular expression parser: conditional subpatterns problem
On Mon, 20 Sep 2010, Oleg Sychev wrote:

> I'm trying to develop a PCRE-compatible regular expression parser. I have
> run into trouble considering conditional subpatterns:
> (?(assert)yes-expr|no-expr)
> There is conflict between | as a alternative operator in expression and | as
> a delimeter between yes and no expressions. The docs says it gives parse
> error if there is more than two alternatives in expression. However, nothing
> is said about is using alternative in subpattern inside expression valid or
> not, i.e. is this expression valid
> (?(?=a)(b|c)|d)


Yes, it is valid. You could have tested it using the pcretest test
program.

> I found no docs at all on this. Please clarify you syntax.


I have made a note to add to the documentation that the restriction is
to two "top-level" alternatives within the subpattern; within these
alternatives, sub-alternatives are allowed as often as you like (and
indeed could contain their own nested conditional subpatterns if you
really were getting complicated).

Philip

--
Philip Hazel