Boost logo

Boost Users :

From: sdf sdf (myspamhere_at_[hidden])
Date: 2003-07-17 05:29:30


Hellos everyone! Here is a good one.

I am using regex and am having some weird returns. I
can assign my results to a std:vector <std:string>.
The vector[0] does contain the correct match, but
vector[1] does not contain what is in a set of
parentheses as it should. In fact I usually get a
segment fault when I try to access it.

I then found I can access results from the grep by
using the boost::Regex.What(n). However What(0)
returns the next available match in the string, and
What(1) and up will correctly report the substrings
defined in this second match correctly.
If no second match is available then the What() member
will return the original match.

How do I fix the vector problem?
OR?
Does using What() force another search to take place?
And if so can I change that behavior?

Code snippet:

string reg_string ="[0-9]{3}(-[0-9]{2}-)[0-9]{4}";
//yes it is a SSN
string search_string = "Big Bird \n123 sesame street
\n the bronx NY
11722\n545-65-2343\nmorestuff\nandevenmore\nSnuff E
Lufigous \n 234 sesame street \n the bronx NY
11722\n889-99-5527\nmorestuff\nandevenmore\n";

std::vector<std::string> results;
boost::regex regsearch =
boost::regex(reg_string,false);
int num_matchs;

num_matchs=regsearch.Grep(results, search_string,
boost::match_any);

cout << num_matchs << " Number of Matchs\n"; // this
is 2
cout << results[0] << " results return string
vector[0] \n"; // this is 545-65-2343
cout << regsearch.What(0) << " results from what(0)
\n"; // this is 889-99-5527
cout << regsearch.What(1) << "results from what(1)
\n";// this is -99-
//this line aborts
// cout << results[1] << " results return string
vector[1] \n"; // this should be -65-

HELP.

Note I never ran the code above, but I think it is
correct.

__________________________________
Do you Yahoo!?
SBC Yahoo! DSL - Now only $29.95 per month!
http://sbc.yahoo.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