[hadoop@iZ25s7cmfyrZ C_script]$ cat poco_regularexpression.cpp
#include <Poco/RegularExpression.h>
#include <iostream>
using Poco::RegularExpression;
int main(int argc, char** argv)
{
RegularExpression p("[0-9]+");
std::string numstr="12345ghk89760";
std::string s;
int n=p.extract(numstr,s); //n=1, s=12345
std::cout << n << std::endl;
std::cout << s << std::endl;
n=p.math(numstr); // n=0;
n=p.subst(numstr,"*"); //numstr="*ghk89760"
RegularExpression::Match pos;
n=p.match(numstr,0,pos); // n=1; pos.offset=0, pos.length = 5
std::cout << n << std::endl;
std::cout << pos.offset <<std::endl;
std::cout << pos.length << std::endl;
n=1;
int of=0;
while(n) //0 12345 \n 5 89760 \n 13
{
n=p.match(numstr,of,pos);
//p.subst(numstr,"*");
p.extract(numstr,of,s);
std::cout << of << "\t" << s << std::endl;
of=pos.offset + pos.length;
}
n=1;
while(n) //"*ghk89760" \n "*ghk*"
{
n=p.subst(numstr,"*");
std::cout << numstr << std::endl;
}
}