|
Boost Users : |
From: david v (danova_fr_at_[hidden])
Date: 2007-07-04 06:00:25
Ok i understand david and divad is the same so it's normal to find it twice,
however why it always return as match "David" and not both matches "david"
and "divad" in the order they appear in the searched string??? does not make
sense to me ?? How can i get the matches in the same order they appear in
the string ??
david v wrote:
> > Hello,
> > I'm trying to use regex_search to look for regular expressions.
> >
> > regex = (david|divad)
> > stringtosearch = "david"
> >
> >
> > So I'm looking for regex above in the string "david". As you see a
> > very basic example. I'm expecting to find two hits, but I thought I
> > should recover "david" and "david" and not twice the same match
> > "david" ???
> >
> > Here is a snippet of the code:
> >
> > ....
> > boost::smatch match;
> > start = stringtosearch.begin(); //that would be the start of "david"
> > end = stringtosearch.end(); // that would be the end of "david"
> > old_pos = 0;
> > cout << "Looking for regex:" << regex << " in string " <<
> > stringtosearch << endl;
> > while (boost::regex_search(start,end,match,regex))
> > {
> >
> >
> > old_pos += match.position()+1;
> > std::string t = match[0];
> >
> > std::cout << "\tFound:" << match[0] << endl;
> >
> > old_pos += match.length();
> > start = match[0].second;
> >
> >
> > }
> > catch(const std::exception ®ex)
> > {
> > std::cerr << "Exception:" << regex.what() << std::endl;
> > exit(-1);
> > }
> >
> >
> > Here is the output:
> > Looking for regex:(david|divad) in string david
> > Found david
> > Looking for regex:(david|divad) in string david
> > Found david
> >
> > As you can see, pattern "david" is found twice ??? I was expecting two
> > different patterns to be found "david" and "divad".
Um, because the stringtosearch contains "divad" both times the code is
called?
> > cout << "Looking for regex:" << regex << " in string " <<
> > stringtosearch << endl;
Outputs
> > Looking for regex:(david|divad) in string david
Both times.
> > By the way how can I recover the total number of matches found ??
By keeping count?
John.
_________________________________________________________________
Testez Windows Live Mail Beta ! http://www.ideas.live.com/
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