AMDG Florian Schwarz wrote:
the non-greedy matching seems to have a weird behaviour (maybe non-determeterministic?) to work if the pattern is preceeded with something.
Boost.Regex doesn't guarantee that it finds the longest possible match. perl does exactly the same thing: $ perl -e '$x = "hhallo"; $x =~ s/h(.*?)o?/$1/g; print $x;' allo
E.g. when I want to get all characters in a string except the last on, if its an 'o', I would use regex matchExpr("(.*?)o?"); So if I write string text("hallo"); regex matchExpr("(.*?)o?"); string valueExpr("$1"); string result; regex_replace(back_inserter(resul), text.begin(), text.end(), matchExpr, valueExpr); cout << "Match \"" << result << "\"" << endl; it will print the expected "hall". If I now use instead string text(" hallo"); regex matchExpr(" (.*?)o?"); it will print "hallo". And for string text("hhallo"); regex matchExpr("h(.*?)o?"); string valueExpr("$1"); regex_replace(back_inserter(resul), text.begin(), text.end(), matchExpr, valueExpr); cout << "Match \"" << result << "\"" << endl; it will print "allo" which seems even more strange to me.
In this case, the regex matches each 'h'. In Christ, Steven Watanabe