|
Boost Users : |
From: Scott McCaskill (scott_at_[hidden])
Date: 2003-09-23 19:03:49
I seem to be having some trouble with the regex library:
#include <boost/regex.hpp>
#include <cassert>
#include <iostream>
int main(int argc, char* argv[])
{
using namespace boost;
cmatch what;
assert(regex_match("foo: bar", what, regex("([\\w]+):[\\s]*(.*)")));
assert(what.size() == 3);
assert(what[1].matched);
assert(what[2].matched);
assert(std::string("foo") == std::string(what[1]));
std::cout << std::string(what[2]) << "\n";
assert(std::string("bar") == std::string(what[2])); // fails
return 0;
}
The last assert always fails, because regex::match insists on including the
space after the ":" in the second match result, which seems wrong to me.
I've tried giving various different combinations of flags to the regex ctor,
although from what I can tell from the documentation the default flags
should work. This is with VC7 and boost 1.30.2. For comparison, perl
(5.6.1) does not seem to have this problem, as the following script
illustrates:
#!/usr/bin/perl
print "matches: <$1> <$2>\n" if ('foo: bar' =~ /([\w]+):[\s]*(.*)/);
Is there any way to get the behavior I want?
Thanks,
Scott McCaskill
Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net