Boost version 1.60.0 gcc 4.8.4
When I construct a boost::regex object with the string: .*{
I get an exception stating that:
what(): Missing } in quantified repetition. The error occurred while parsing the regular expresion: '.*{>>>HERE>>>'.
This error occurs when the object is a boost::regex::extended
type, but not if it is boost::regex::perl
.
So the following throws the exception:
regString(".*{");
boost::regex reg_e(regString, boost::regex::extended);
but this does not:
regString(".*{");
boost::regex reg_p(regString, boost::regex::perl);
Is this expected behavior or a bug?
If it is expected, why? and what is an appropriate work around?
{
is a special character in this context , you need to escape it.
http://www.boost.org/doc/libs/1_60_0/libs/regex/doc/html/boost_regex/syntax/perl_syntax.html
Note that the "{" and "}" characters will treated as ordinary literals when used in a context that is not a repeat: this matches Perl 5.x behavior. For example in the expressions "ab{1", "ab1}" and "a{b}c" the curly brackets are all treated as literals and no error will be raised.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.