AMDG Jeff Anderson wrote:
I'm trying to use a non-greedy quantifier in a regex. Here is an example from my code:
string input=string("/blog/2008/../"); string expr=string("/.*?/\\.\\./"); string replacement=string("/"); std::ostringstream stream(std::ios::out | std::ios::binary); std::ostream_iterator
stream_iterator(stream); boost::regex pattern(expr, boost::regex::perl); boost::regex_replace(stream_iterator, input.begin(), input.end(), pattern, replacement, boost::match_default | boost::format_all); string result=stream.str();
The expected output is "/blog/". I am getting "/".
So, non-greedy repeats stop as soon as they can. However, when doing a regex_replace, the library always finds the first occurrence of the pattern. In other words greediness does not affect the place where the match begins it only affects how soon the match ends. I think that this regex does what you want: std::string expr("/[^/]*/\\.\\./"); In Christ, Steven Watanabe