#include "pcre++.h"
#include <iostream>
int main() {
try {
string expression = "([a-z]*) ([0-9]+)";
string stuff[] = { "hallo 11 robert", "so what?", "hey 123" };
Pcre reg(expression, "i");
for(int st=0; st < 3; st++) {
cout << endl << "search on \"" << stuff[st] << "\" ";
if(reg.search(stuff[st]) == true) {
if(reg.num_matches > 1) {
cout << "matched " << reg.matches() << " times:" << endl;
ResultSet *results = reg.get_sub_strings();
int _pos = 0;
for(ResultIterator p = results->begin(); p != results->end(); ++p) {
string match = *p;
cout << " Iterator match " << _pos++ << ": " << match << endl;
}
cout << endl;
for(int pos=0; pos < reg.matches(); pos++) {
cout << " Class match " << pos << ": " << reg.get_match(pos) << endl;
cout << " start: " << reg.get_match_start(pos) << ", end: " << reg.get_match_end(pos) << endl;
}
}
else {
cout << "it matched, there where no substrings." << endl;
}
}
else {
cout << "didn't match." << endl;
}
}
}
catch (Exception E) {
cerr << E.mout() << endl;
exit(-1);
}
exit(0);
}