Boost logo

Boost Users :

From: Golan Trevize (G.Trevize_at_[hidden])
Date: 2007-10-26 16:07:51


Hello.

First... I'm sorry for my english. And second - I've got small problem.

I need use regexp. The idea is that I use 'replace', it find some text like in expression and this will be an input for function... then in function something happen and output of the function replace in text the input of the function...

For example I've got text "Solution: 5 and 4". Regular expression is "[0-9]" And the function is "add5"
int add5(int input){return input+5}
And the output of this function replace the number with number+5... And in the end text will be: "Solution: 10 and 9"

In C++ with Boost? I don't know how can I do it...

something like this....

#include <cstdlib>
#include <iostream>
#include <boost/regex.hpp>

using namespace std;
using namespace boost;

// the callback function
string add5(string x)
{
int v;
v =atoi(x.c_str()) + 5;
string vystup = (char *)v;
return vystup;
}

int main(int argc, char *argv[])
{
string t;
string k;
t = "Solution: 4";

regex expression("[0-9]");

k=regex_replace(t, expression,add5, boost::match_default|boost::format_all);

cout << k << endl;

system("PAUSE");
return EXIT_SUCCESS;
}

How can I rewrite this line:

k=regex_replace(t, expression,add5, boost::match_default|boost::format_all);

And how I change the callback function add5...

If someone know, thank you for answers and advices.


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