Trying to re-write a php function to C++ using boost.. I have NOT seen code for this anywhere on the net. I thought it was useful and I need it for C++ but I need help..
definition of the function in c++
void preg(string pattern, string subject, string &matches, int flags, int offset) //Matches is a 2D array or map or 2d vector..
{
}
Function I want to re-write to C++..
http://php.net/manual/en/function.preg-match-all.php
Attempt (takes in a string, matches it to an expression, returns the match:
string ID; //Match to be returned.
string Source; //Source of Data to match against..
boost::regex expression("(.*)"); //A patter to match..
void preg_match_all(string Source, boost::regex &expression, string &ID)
{
try
{
std::string::const_iterator start, end;
start = Source.begin();
end = Source.end();
boost::smatch what;
boost::match_flag_type flags = boost::match_default;
//Match against the data.. if a match is found, return it to ID..
while(boost::regex_search(start, end, what, expression, flags))
{
//Destination = boost::regex_replace(Source, expression, "");
ID = what[0];
start = what[0].second;
}
}
catch(exception &e)
{
cout<<"Exception Caught.. Function: preg_match_all.\n\n";
}
return;
}
Problem.. I want it to return an array of every match it finds.. At the moment it returns one match..
Example Data:
<td vsgsgs> whatever else here</td><td>fsgsgs</td><td aifngn;aga></td>
It will return that whole thing into the string ID. I want it to return:
array[0] = <td vsgsgs> whatever else here</td>
array[1] = <td>fsgsgs</td>
array[2] = <td aifngn;aga></td>