An example of performing regex match against a pattern with JPCRE2 and getting the match count and match results.
More...
An example of performing regex match against a pattern with JPCRE2 and getting the match count and match results.
Shows how to iterate over the match results to get the captured groups/substrings.
#include <iostream>
int main(){
re.
setPattern(
"((?<spc>[.?#@])|(?<w_s>\\w+))\\s*(?<digit>\\d+)")
std::string subject = "(I am a string with words and digits 45 and specials chars: ?.#@ 443 অ আ ক খ গ ঘ 56)";
size_t count = 0;
std::cout<<"\nTotal number of mathces: "<<count<<std::endl;
for(size_t i=0;i<vec_num.size();++i){
std::cout<< "\n################## Match no: "<<i+1<<" ####################\n";
std::cout<<"\n-------------------------------------------------------------------------";
std::cout<< "\n--- Numbered Substrings (number: substring) for match "<<i+1<<" ---\n";
for(size_t j=0;j<vec_num[i].size();++j){
std::cout<<"\n\t"<<j<<": "<<vec_num[i][j]<<"\n";
}
std::cout<<"\n-------------------------------------------------------------------------";
std::cout<< "\n--- Named Substrings (name: substring) for match "<<i+1<<" ---\n";
for(jp::MapNas::iterator ent=vec_nas[i].begin();ent!=vec_nas[i].end();++ent){
std::cout<<"\n\t"<<ent->first<<": "<<ent->second<<"\n";
}
std::cout<<"\n-------------------------------------------------------------------------";
std::cout<< "\n--- Name to number mapping (name: number/position) for match "<<i+1<<" ---\n";
for(jp::MapNtN::iterator ent=vec_ntn[i].begin();ent!=vec_ntn[i].end();++ent){
std::cout<<"\n\t"<<ent->first<<": "<<ent->second<<"\n";
}
}
return 0;
}
- Author
- Md Jahidul Hamid