$include_dir="/home/hyper-archives/boost-users/include"; include("$include_dir/msg-header.inc") ?>
Subject: Re: [Boost-users] [regex] validating expressions
From: Jeff Flinn (TriumphSprint2000_at_[hidden])
Date: 2010-05-20 12:36:31
John Dlugosz wrote:
>> 	"[[[A-Z]]"
>> 	"[A-Z]??"
>>
>> Both Qt's QRegExp and http://www.regexplanet.com/simple/index.html
>> report the first is invalid. Qt's QRegExp reports the second as
>> invalid,
>> while http://www.regexplanet.com/simple/index.html report it as valid.
> 
> The second one is using a feature that changes the greediness of the quantifiers.  You might look at the "perlre" man page for Perl 5.10 to get more complete documentation.
> 
> === quote ===
> By default, a quantified subpattern is "greedy", that is, it will match as many times as possible (given a particular starting location) while still allowing the rest of the pattern to match. If you want it to match the minimum number of times possible, follow the quantifier with a "?". Note that the meanings don't change, just the "greediness":
> 
>     *?     Match 0 or more times, not greedily
>     +?     Match 1 or more times, not greedily
>     ??     Match 0 or 1 time, not greedily
>     {n}?   Match exactly n times, not greedily
>     {n,}?  Match at least n times, not greedily
>     {n,m}? Match at least n but not more than m times, not greedily
> === end quote ===
> 
> The first one is not an error because a ']' by itself is just a literal character, and '[' is fine inside the range.  [[[A-Z] is a range, just like [xxA-Z] is.  
> 
> --John
Thanks John, I'll take a look.
Jeff