JPCRE2  10.32.01
C++ wrapper for PCRE2 library
test_replace2.cpp File Reference
#include <iostream>
#include "jpcre2.hpp"
+ Include dependency graph for test_replace2.cpp:

Detailed Description

Contains an example to take subject string, replacement string, modifier and pattern from user input and perform regex replace with JPCRE2

#include <iostream>
#include "jpcre2.hpp"
void getLine(std::string& a) { std::getline(std::cin,a,'\n'); }
int main(){
std::string pat,mod,subject,repl,repl_mod;
std::cout<<"\nEnter pattern: ";
getLine(pat);
std::cout<<"\nEnter compile modifiers (eijmnsuxADJSU): ";
getLine(mod);
jp::Regex re;
// Compile the pattern
re.compile(pat,mod);
//check if it was a success
if(!re){std::cerr<<re.getErrorMessage();}
//if(re) is only available for >=C++11, use if(!!re) as an alternative
/* // >= C++11
if(re) std::cout<<"\n Success";
else std::cerr<<"\n Failure";
*/
if(!!re) std::cout<<"\n Compile Success";
else std::cout<<"\n Compile Failure";
// subject string
std::cout<<"\nEnter subject string (enter quit to quit): "<<std::endl;
getLine(subject);
if(subject=="quit")return 0;
//replacement string
std::cout<<"\nEnter replacement string: "<<std::endl;
getLine(repl);
std::cout<<"\nEnter action (replacement) modifiers (eEgx): ";
getLine(repl_mod);
//perform replace
std::cout<<"\nreplaced string: "<<
rr.setRegexObject(&re)
.setSubject(subject)
.setReplaceWith(repl)
.addModifier(repl_mod)
.replace();
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