|
Boost : |
From: Chris (chris_at_[hidden])
Date: 2001-04-29 21:25:29
Hiya,
I've been messing with boost's regex class, but I can't figure out
sub-expressions for the life of me. I understand that I call
regex_match(), and pass it a match_results, but I just don't
understand match_results - particularly struct sub_match .
For example, look at this little piece of code . . .
#include <iostream>
#include <boost\regex.hpp>
using namespace boost;
using namespace std;
int main(int argc, char* argv[])
{
regex rxHeader("(\\w+), (\\w+)");
cmatch matches;
if (regex_match("Moose, Orangutang", matches, rxHeader))
{
cout << matches[1].first << endl;
}
else
puts("No match.");
return 0;
}
I expect matches[1].first to return "Moose", the first match. But it
doesn't - it returns "Moose, Orangutang". matches[2].first returns
"Orangutang", which makes some sense.
Actually, I don't understand this whole first/second business in
sub_matches. In any other language, matches[0] would just be a string
or something. But here, obviously things are being done differently,
and just don't understand what the scheme is here. I've read the docs
over and over, and I can't find a darn thing.
Any help?
Thanks,
Chris
Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk