Boost logo

Boost :

From: Stephan T. Lavavej (stl_at_[hidden])
Date: 2003-12-31 19:47:04


Asking for non-greedy repeats can change /whether/ an expression matches,
which seems to be blatantly wrong.

C:\Temp\boost>type test.cc
#include <iostream>
#include <boost/regex.hpp>
using namespace std;
using namespace boost;

int main() {
    cout << regex_match("a", regex(".*")) << endl;
    cout << regex_match("a", regex(".*?")) << endl;
}

C:\Temp\boost>g++ -Wall -W test.cc -o test.exe -lboost_regex

C:\Temp\boost>test
1
0

C:\Temp\boost>

This was originally encountered when trying to strip leading and trailing
whitespace from a string in one step. It turns out that

regex_merge(s, regex("\\A\\s*(\\S*(\\s+\\S+)*)\\s*\\z"), "$1");

will work correctly, but the "obvious"

regex_merge(s, regex("\\A\\s*(.*?)\\s*\\z"), "$1", format_no_copy);

does not:

"x" => ""
" x" => ""
"x " => "x"
" x " => "x"

(The format_no_copy flag is present so you can see what is really
happening.)

I'm almost certain that the first example is a Boost bug, I'm reasonably
confident that the second example is also a Boost bug, and I think that they
are both instances of the same problem.

Stephan T. Lavavej
http://nuwen.net


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk