|
Boost Users : |
Subject: Re: [Boost-users] [regex] stuck with expression syntax / exception
From: John Maddock (jz.maddock_at_[hidden])
Date: 2015-03-14 13:02:31
On 14/03/2015 16:31, Thomas wrote:
> Hi,
>
> I am pretty much a complete novice to the boost::regex library, and
> stuck with the following snippet:
>
> std::string String = " (of 1000 elements; 67.10%)";
> try
> {
> std::cout << boost::regex_match(String, boost::regex("^ (of \\d+
> elements; .+%)$")) << std::endl;
> std::cout << boost::regex_match(String, boost::regex(" (of \\d+
> elements;.+")) << std::endl;
> }
> catch(boost::regex_error const &)
> {
> std::cout << "caught boost::regex_error!";
> }
>
> Two questions:
> First, why does the first not match?
The "(" characters are grouping operators, use "\\(" for a literal (.
> Second, why does the second throw?
Well if you'd printed out the message contained in the exception it
would have told ;)
Same reason as above: you have a grouping ( start but no matching ).
John.
>
> The idea of the regex is that the first number is an integer, and for
> the percentage number the formatting is unspecified but must terminate
> with '%'; otherwise all characters must match exactly.
>
> thanks,
> Thomas
>
>
> _______________________________________________
> 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