
I have having a problem determining if the regex library is working properly. I have run the regex regression tests, and all tests in the test.txt file pass. My problem however began with the following match: string: "orange and ba.ana and kiwi" expression: "\\.([a-z]+).*[ \t\n].*\\.([a-z]+)" expected result: match, captures 'range' and 'ana' real result: no match The code in question is this: bool result = false; std::string str = "orange and ba.ana and kiwi"; std::string exp(".([a-z]+).*[ \t\n].*\\.([a-z]+)"); try { boost::smatch what; boost::regex e(exp.c_str()); // use default format flags result = regex_match(str, what, e); if (result) { ... } } catch (std::runtime_error &e) { ... } ... It seems to consistently fail. This same example works in both Java and Perl, and with the PCRE C++ regex library. No exception is being caught either. I posted the actual code to show that i don't think i'm doing anything particularly unique - i call regex_match (though even regex_search fails to match). I even tried formatting a file for the regression test harness with this example, and it confirmed that this particular example does not succeed. Can someone please provide suggestions regarding: a) what is going wrong b) how to fix it It should be noted that i'm running linux, boost version 1.31.0, with the regex patch installed. Thanks.

On Sun, 12 Sep 2004 12:53:56 -0400 (EDT), Andrew Dennison
string: "orange and ba.ana and kiwi" expression: "\\.([a-z]+).*[ \t\n].*\\.([a-z]+)"
Looks like you mean "." at the beginning, not "\\." judging by the code below.
expected result: match, captures 'range' and 'ana' real result: no match
The code in question is this: [ ... ] result = regex_match(str, what, e);
According to the documentation, regex_match only finds matches that
consume ALL of the input text. You want regex_search. A test program
is attached. I double-backslashed the \t and \n, but verified that
either version works.
#include <string>
#include <iostream>
#include <iterator>
#include

It seems to consistently fail. This same example works in both Java and Perl, and with the PCRE C++ regex library. No exception is being caught either.
I posted the actual code to show that i don't think i'm doing anything particularly unique - i call regex_match (though even regex_search fails to match). I even tried formatting a file for the regression test harness with this example, and it confirmed that this particular example does not succeed.
Can someone please provide suggestions regarding: a) what is going wrong b) how to fix it
It should be noted that i'm running linux, boost version 1.31.0, with the regex patch installed.
It works for me, *only* if you use regex_search (see code below), the reason
that you need to use regex_search is that the match found is only a prefix
of the string, and regex_match will only succeed if the *whole* of the
string is matched.
John.
And here's the code:
#include <string>
#include <iostream>
#include <iomanip>
#include
participants (3)
-
Andrew Dennison
-
Caleb Epstein
-
John Maddock