Boost logo

Boost Users :

From: Peter Boot (peter.boot_at_[hidden])
Date: 2008-07-14 21:16:30


got it, thanks

On Tue, Jul 15, 2008 at 2:10 AM, Eric Niebler <eric_at_[hidden]>
wrote:

> Peter Boot wrote:
>
>> Is there functionality included in boost::xpressive::regex_search(...)
>> that would allow you to know which of an alternated group of expressions
>> e.g. "aaa|bbb|ccc" matched a substring in the input ?
>>
>
> Just as with Perl and with Boost.Regex, you could create backreferences and
> check to see which participated in the match:
>
> "(aaa)|(bbb)|(ccc)"
>
> Then pass a match_results<> object to regex_search and check
> "what[N].matched" for N=1,2,3 (assuming your match_results<> object was
> named "what").
>
> If the alternates are all string literals, then you can use an xpressive
> symbol table instead and discover which alternate matched more efficiently.
> For that you'd initialize a std::map with your alternates ...
>
> std::map<string,int> syms;
> syms["aaa"] = 1;
> syms["bbb"] = 2;
> syms["ccc"] = 3;
> int which = 0;
>
> // Match a symbol, write the corresponding
> // integer into "which"
> sregex rx = (a1= syms)[ ref(which) = a1 ];
>
> HTH,
>
> --
> Eric Niebler
> BoostPro Computing
> http://www.boostpro.com
> _______________________________________________
> Boost-users mailing list
> Boost-users_at_[hidden]
> http://lists.boost.org/mailman/listinfo.cgi/boost-users
>



Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net