An example of doing regex replace with JPCRE2
#include <iostream>
int main(){
re.setPattern("(?:(?<word>[?.#@:]+)|(?<word>\\w+))\\s*(?<digit>\\d+)")
.addModifier("Jin")
.addPcre2Option(0)
.compile();
if(!re){std::cerr<<re.getErrorMessage();}
std::string s="I am a string with words and digits 45 and specials chars: ?.#@ 443 অ আ ক খ গ ঘ 56";
std::cout<<"\nreplaced string: \n"<<
rr.setRegexObject(&re)
.setSubject(&s)
.setReplaceWith("(replaced:$1)(replaced:$2)(replaced:${word})")
.addModifier("xEafds")
.addPcre2Option(0)
.replace();
if(rr.getErrorNumber() != 0)
std::cerr<<"\n"<<rr.getErrorMessage();
return 0;
}
- Author
- Md Jahidul Hamid