 |
JPCRE2
10.32.01
C++ wrapper for PCRE2 library
|
#include <iostream>
#include "jpcre2.hpp"
Contains some short examples of performing regex match and regex replace with JPCRE2
#include <iostream>
int main(){
size_t count;
if(
jp::Regex(
"(\\d)|(\\w)").match(
"I am the subject"))
std::cout<<"\nmatched";
std::cout<<"\n"<<
count =
std::cout<<"\nNumber of matches: "<<count;
std::cout<<"\nTotal match of first match: "<<vec_num[0][0];
std::cout<<"\nCaptured group 1 of first match: "<<vec_num[0][1];
std::cout<<"\nCaptured group 2 of first match: "<<vec_num[0][2];
std::cout<<"\nTotal match of second match: "<<vec_num[1][0];
std::cout<<"\nCaptured group 1 of second match: "<<vec_num[1][1];
std::cout<<"\nCaptured group 2 of second match: "<<vec_num[1][2];
re.compile("(?<word>\\w+)\\s*(?<digit>\\d+)","m");
count =
std::cout<<"\nNumber of matches: "<<vec_nas.size();
std::cout<<"\nCaptured group (word) of first match: "<<vec_nas[0]["word"];
std::cout<<"\nCaptured group (digit) of first match: "<<vec_nas[0]["digit"];
std::cout<<"\nCaptured group (word) of second match: "<<vec_nas[1]["word"];
std::cout<<"\nCaptured group (digit) of second match: "<<vec_nas[1]["digit"];
std::cout<<"\nPosition of captured group (word) in first match: "<<vec_ntn[0]["word"];
std::cout<<"\nPosition of captured group (digit) in first match: "<<vec_ntn[0]["digit"];
std::cout<<"\n"<<
std::cout<<"\n"<<
std::cout<<"\n"<<
.
replace(
"I am the subject\tTo be swapped according to tab",
"$2 $1");
re.compile("^([^\t]+)\t([^\t]+)$");
return 0;
}
- Author
- Md Jahidul Hamid
String replace(String const &mains, String const &repl, Modifier const &mod="", SIZE_T *counter=0)
Perform regex replace and return the replaced string using a temporary replace object.
Definition: jpcre2.hpp:4285
virtual RegexMatch & setNameToNumberMapVector(VecNtN *v)
Set a pointer to the name to number map vector.
Definition: jpcre2.hpp:1732
virtual RegexMatch & setNamedSubstringVector(VecNas *v)
Set a pointer to the named substring vector.
Definition: jpcre2.hpp:1721
SIZE_T match(String const &s, Modifier const &mod, PCRE2_SIZE start_offset=0)
Perform regex match and return match count using a temporary match object.
Definition: jpcre2.hpp:4227
virtual RegexMatch & setSubject(String const &s)
Set the subject string for match.
Definition: jpcre2.hpp:1762
String replace(void)
Perform regex replace by retrieving subject string, replacement string, modifier and other options fr...
Definition: jpcre2.hpp:4654
RegexReplace & setReplaceWith(String const &s)
Set the replacement string.
Definition: jpcre2.hpp:3261
virtual RegexMatch & setModifier(Modifier const &s)
Set the modifier (resets all JPCRE2 and PCRE2 options) by calling RegexMatch::changeModifier().
Definition: jpcre2.hpp:1790
std::vector< NumSub > VecNum
Vector of matches with numbered substrings.
Definition: jpcre2.hpp:1279
Provides public constructors to create RegexReplace objects.
Definition: jpcre2.hpp:2890
Main header file for JPCRE2 library to be included by programs that uses its functionalities....
virtual SIZE_T match(void)
Perform match operation using info from class variables and return the match count and store the resu...
Definition: jpcre2.hpp:4776
RegexReplace & setSubject(String const &s)
Set the subject string for replace.
Definition: jpcre2.hpp:3227
Provides public constructors to create Regex object.
Definition: jpcre2.hpp:3550
virtual RegexMatch & setNumberedSubstringVector(VecNum *v)
Set a pointer to the numbered substring vector.
Definition: jpcre2.hpp:1710
struct to select the types.
Definition: jpcre2.hpp:1238
std::vector< MapNtN > VecNtN
Vector of substring name to substring number map.
Definition: jpcre2.hpp:1275
Provides public constructors to create RegexMatch objects.
Definition: jpcre2.hpp:1375
std::vector< MapNas > VecNas
Vector of matches with named substrings.
Definition: jpcre2.hpp:1273