Boost logo

Boost Users :

From: Peter Sliepenbeek (peter_sliepenbeek_at_[hidden])
Date: 2006-04-06 09:50:45


First some examples:

--
std::string input = "u";
std::string expression = "[^UuMmFf]*";
std::string replacement = "Unknown";
boost::regex regular_expression(expression);
std::string output = boost::regex_replace(input,
regular_expression,
replacement, boost::match_default);
Boost: output = "UnknownuUnknown"
$ echo 'u' | sed 's/[^UuMmFf]*/Unknown/g'
UnknownuUnknown
Expected.
--
std::string input = "x";
std::string expression = "[^UuMmFf]*";
std::string replacement = "Unknown";
boost::regex regular_expression(expression);
std::string output = boost::regex_replace(input,
regular_expression,
replacement, boost::match_default);
Boost 1.33.1: output = "UnknownUnknown"
Prior: "Unknown"
$ echo 'x' | sed 's/[^UuMmFf]*/Unknown/g'
Unknown
The result generated by Boost 1.33.1 is not expected!
--
std::string input = " ";
std::string expression = "[^UuMmFf]*";
std::string replacement = "Unknown";
boost::regex regular_expression(expression);
std::string output = boost::regex_replace(input,
regular_expression,
replacement, boost::match_default);
Boost 1.33.1: output = "UnknownUnknown"
Prior: "Unknown"
$ echo ' ' | sed 's/[^UuMmFf]*/Unknown/g'
Unknown
The result generated by Boost 1.33.1 is not expected!
--
The expression "[^UuMmFf]*" will greedily match the
input string. In the
case of "x" or " " (space) the expression will match
the whole string! There
should not be a match on an empty string!
Considering these examples I would mark this as a bug!
Thanks,
P. Sliepenbeek
__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

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