JPCRE2  10.32.01
C++ wrapper for PCRE2 library
test_replace.cpp File Reference
#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
jpcre2::select::RegexReplace
Provides public constructors to create RegexReplace objects.
Definition: jpcre2.hpp:2890
jpcre2.hpp
Main header file for JPCRE2 library to be included by programs that uses its functionalities....
jpcre2::select::Regex
Provides public constructors to create Regex object.
Definition: jpcre2.hpp:3550
jpcre2::select
struct to select the types.
Definition: jpcre2.hpp:1238