
On Sun, 12 Sep 2004 12:53:56 -0400 (EDT), Andrew Dennison <adenniso@csd.uwo.ca> wrote:
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 <boost/regex.hpp> using namespace std; using namespace boost; int main () { string str = "orange and ba.ana and kiwi"; try { smatch what; regex e (".([a-z]+).*[ \\t\\n].*\\.([a-z]+)"); bool result = regex_search (str, what, e); if (result) cout << "Matched: " << what.format ("`$1' `$2'") << "\n"; else cout << "No match for " << e << " in " << str << "\n"; } catch (std::runtime_error& e) { cerr << e.what () << "\n"; } return 0; } Output: Matched: `range' `ana' -- Caleb Epstein caleb.epstein@gmail.com