
Renjie Zhao wrote:
After downloading boost_1_33_1, I succeeded in building regex lib with both VC8 and GCC 3.4.2(mingw special)
1st: The following code, which is compiled ok using VC8 (cl a.cpp/I"F:\boost_1_33_1" /EHsc), gives out wrong answer. Well I think the answer is wrong. Do I misunderstand the regular expression? It says"no match" while it is supposed to match twice. 01234 and 56972. If I changes the regex expr to ".*", the code functions well and gives out: The (0) match is:01234abcd56972
What is the problem?
You're doing two things completely wrong: 1) regex_match will find one match only if it is a match against the *whole of the supplied string*. To find a match against a sub-set of the supplied string use regex_search. 2) The match_results structure contains matches for *marked sub-expressions*, only one match is found with regex_search/regex_match. To find multiple matches you iterate through them with regex_iterator or regex_token_iterator.
2nd: I got a lot of error messages when I tried to compile the same piece of code with GCC 3.4.2 (mingw-special) under windows 2003 and GCC 4.1.0-3 (shipped with Fedora Core 5) under Linux. The previous work using Boost::regex is to build the lib, under windows and linux, the work is done with no error.
------------------error message under windows:------------------------- F:\projects> g++ a.cpp -I"F:\boost_1_33_1" -o a.exe
You haven't supplied a regex lib to link against. Consult your gcc manual for that one. John.