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

Detailed Description

An example of performing regex match and regex replace with std::wstring and std::u16string.

#include <iostream>
#include "jpcre2.hpp"
#include <sstream>
typedef jpcre2::select<wchar_t> jpw; //for windows it's 16
#if __cplusplus >= 201103L
typedef jpcre2::select<char16_t> jpu; //sizeof(char16_t)*CHAR_BIT will be taken as default value for BS
int main() {
//Working with wchar_t i.e std::wstring
//In Linux this will require 32-bit library to be linked, because, wchar_t is 32 bit in Linux.
jpw::Regex(L"[\\w]+").match(L"I am a subject with 7 matches", "g"); //modifier is always std::string
jpw::Regex(L"subject").replace(L"I am a subject",L"string (got replaced)");
#if __cplusplus >= 201103L
//Working with char16_t i.e std::u16string (>=C++11)
jpu::Regex(u"[\\w]+").match(u"I am a subject with 7 matches", "g"); //modifier is always std::string
std::u16string us = jpu::Regex(u"subject").replace(u"I am a subject", u"string (got replaced)");
std::wcout<<L"\n"<<std::wstring(us.begin(), us.end()); //naive conversion, will work for this example.
return 0;
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
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
Main header file for JPCRE2 library to be included by programs that uses its functionalities....
Provides public constructors to create Regex object.
Definition: jpcre2.hpp:3550
struct to select the types.
Definition: jpcre2.hpp:1238