JPCRE2  10.31.02
C++ wrapper for PCRE2 library
test_replace.cpp File Reference

An example of doing regex replace with JPCRE2. More...

#include <iostream>
#include "jpcre2.hpp"
+ Include dependency graph for test_replace.cpp:

Detailed Description

An example of doing regex replace with JPCRE2.

#include <iostream>
#include "jpcre2.hpp"
int main(){
jp::Regex re;
//Compile the pattern
re.setPattern("(?:(?<word>[?.#@:]+)|(?<word>\\w+))\\s*(?<digit>\\d+)") //Set various parameters
.addModifier("Jin") //
.addPcre2Option(0) //...
.compile(); //Finally compile it.
if(!re){std::cerr<<re.getErrorMessage();}
//subject string
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) //set associated Regex object
.setSubject(&s) //Set various parameters
.setReplaceWith("(replaced:$1)(replaced:$2)(replaced:${word})") //...
.addModifier("xEafds") //
.addPcre2Option(0) //...
.replace(); //Finally perform the replace operation.
if(rr.getErrorNumber() != 0)
std::cerr<<"\n"<<rr.getErrorMessage();
return 0;
}
Author
Md Jahidul Hamid