Re: REGEX: grouping of alternative patterns [SOLVED]

From: Date: Tue, 30 Oct 2007 13:33:35 +0000
Subject: Re: REGEX: grouping of alternative patterns [SOLVED]
References: 1 2  Groups: php.general 
Request: Send a blank email to php-general+get-263813@lists.php.net to get a copy of this message
Robin Vickery schreef:
[snip] Because each of your subpatterns can match an empty string, the lefthand subpattern always matches and the righthand subpattern might as well not be there.
Indeed they do, i did not realise that.
The simplest solution, if you don't want to completely rethink your regexp might be to replace \s with [[:space:]], remove the delimiters and the i modifier and just use eregi(). like so: Because this is for a proof-of-concept application that will only be used by me for the time being, and because I always give a default value when specifying 'not null', I'm going to use the following, and think about a more general solution if and when the need arises.
This matches both my cases: /\s*(?.+?)\s*int\s*(\(([0-9]+)\))?\s*(unsigned)?\s*(((not\s*null)\s*(default\s*(.*|[0-9]*)?))|((auto_increment)?\s*(primary\s*key)?))\s*/i
[snip] -robin
Thanks for your insights, Robin ! Greetz, Stijn

« previous php.general (#263813) next »