|
Boost : |
Subject: Re: [boost] Why my subexpression doesn't work in Regex
From: Qihong Wang (qihongwang_at_[hidden])
Date: 2009-03-18 12:24:56
Steve,
I have another question about this. In boost document about Posix basic
regular expression syntax, a section beginning \( and ending \) is
defined as a marked sub-expression. In Posix Extended Regular Expression
Syntax, A section beginning ( and ending ) is defined as a marked
sub-expression. May I say regex class or regex_match support ERE instead of
BRE by default?
Thanks,
Qihong
On Tue, Mar 17, 2009 at 10:43 PM, Steven Watanabe <watanabesj_at_[hidden]>wrote:
> AMDG
>
>
> Qihong Wang wrote:
>
>> I'm a new boost and regex user. I tried a c++ regex sample as follows
>>
>> regex pattern("banan\\(an\\)*a");
>> string str = "bananana";
>>
>> if(regex_match(str, pattern))
>> cout<<"---- pattern matched ----"<<endl;
>> else
>> cout<<"---- pattern unmatched ----"<<endl;
>>
>> To my surprise, the it printed out pattern unmatched. If I change str to
>> "banan(an)a",
>> the result is pattern matched. Feels like boost.Regex doesn't treat ( ) as
>> subexpression.
>> Any idea?
>>
>>
>
> You're escaping the parentheses, so Boost.Regex, treats
> them as literal "(" and ")" instead of special characters.
> The regex will match strings like
> "banan(an)))))a"
>
> In Christ,
> Steven Watanabe
>
> _______________________________________________
> Unsubscribe & other changes:
> http://lists.boost.org/mailman/listinfo.cgi/boost
>
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk