REAL
Regular Expression Algorithmic Library — constexpr C++20 regex
Loading...
Searching...
No Matches
real::compat Namespace Reference

Namespaces

namespace  detail
 
namespace  regex_constants
 Compatibility constants mirroring std::regex_constants (own values, mapped internally).
 

Classes

class  basic_regex
 A std::basic_regex-compatible pattern, backed by real where proven, else std. More...
 
class  match_results
 The result of a match: group sub-matches plus the prefix and suffix. More...
 
class  regex_error
 std::regex_error-compatible exception. More...
 
class  regex_iterator
 Iterates the non-overlapping matches of a pattern in a sequence (std::regex_iterator). More...
 
class  regex_token_iterator
 Enumerates selected sub-matches (or the text between matches) — std::regex_token_iterator. More...
 
class  sub_match
 A matched sub-expression: a [first, second) range into the searched sequence. More...
 

Typedefs

using regex = basic_regex< char >
 The char-path compat regex (real-eligible).
 
using wregex = basic_regex< wchar_t >
 The wide compat regex (always the std backend).
 
using sregex_iterator = regex_iterator< std::string::const_iterator >
 Over a std::string.
 
using cregex_iterator = regex_iterator< const char * >
 Over a C string.
 
using wsregex_iterator = regex_iterator< std::wstring::const_iterator >
 Over a std::wstring (std).
 
using wcregex_iterator = regex_iterator< const wchar_t * >
 Over a wide C string (std).
 
using sregex_token_iterator = regex_token_iterator< std::string::const_iterator >
 Over a std::string.
 
using cregex_token_iterator = regex_token_iterator< const char * >
 Over a C string.
 
using wsregex_token_iterator = regex_token_iterator< std::wstring::const_iterator >
 Over a std::wstring (std).
 
using wcregex_token_iterator = regex_token_iterator< const wchar_t * >
 Over a wide C string (std).
 
using ssub_match = sub_match< std::string::const_iterator >
 Sub-match over a std::string.
 
using csub_match = sub_match< const char * >
 Sub-match over a C string.
 
using wssub_match = sub_match< std::wstring::const_iterator >
 Sub-match over a std::wstring.
 
using wcsub_match = sub_match< const wchar_t * >
 Sub-match over a wide C string.
 
using smatch = match_results< std::string::const_iterator >
 Match over a std::string.
 
using cmatch = match_results< const char * >
 Match over a C string.
 
using wsmatch = match_results< std::wstring::const_iterator >
 Match over a std::wstring (always std).
 
using wcmatch = match_results< const wchar_t * >
 Match over a wide C string (always std).
 

Enumerations

enum class  policy : std::uint8_t { strict , fallback }
 The drop-in policy for a pattern the linear engine cannot represent (backreferences, an unbounded lookaround, a POSIX class, …). strict (the default) rejects it, so every accepted pattern executes each regex_search/regex_match in time linear in the input — the ReDoS-safety guarantee (replace/iterate compose O(n) such operations: quadratic worst-case on any linear engine, never exponential); fallback delegates it to std::regex, which may accept it but forfeits the guarantee for that pattern. More...
 

Functions

template<typename BidirIt >
bool operator== (const sub_match< BidirIt > &lhs, const typename sub_match< BidirIt >::string_type &rhs)
 Equality against an owned string (the common std::sub_match comparison).
 
template<typename BidirIt >
bool operator== (const typename sub_match< BidirIt >::string_type &lhs, const sub_match< BidirIt > &rhs)
 
template<typename BidirIt >
bool operator== (const sub_match< BidirIt > &lhs, const sub_match< BidirIt > &rhs)
 
template<typename BidirIt , typename CharT , typename Traits >
bool regex_search (BidirIt first, BidirIt last, match_results< BidirIt > &m, const basic_regex< CharT, Traits > &re, regex_constants::match_flag_type flags=regex_constants::match_default)
 Leftmost search of [first, last) (Python re.search / std::regex_search).
 
template<typename CharT , typename Traits >
bool regex_search (const std::basic_string< CharT > &s, match_results< typename std::basic_string< CharT >::const_iterator > &m, const basic_regex< CharT, Traits > &re, regex_constants::match_flag_type flags=regex_constants::match_default)
 
template<typename CharT , typename Traits >
bool regex_search (const CharT *s, match_results< const CharT * > &m, const basic_regex< CharT, Traits > &re, regex_constants::match_flag_type flags=regex_constants::match_default)
 
template<typename BidirIt , typename CharT , typename Traits >
bool regex_search (BidirIt first, BidirIt last, const basic_regex< CharT, Traits > &re, regex_constants::match_flag_type flags=regex_constants::match_default)
 
template<typename CharT , typename Traits >
bool regex_search (const std::basic_string< CharT > &s, const basic_regex< CharT, Traits > &re, regex_constants::match_flag_type flags=regex_constants::match_default)
 
template<typename CharT , typename Traits >
bool regex_search (const CharT *s, const basic_regex< CharT, Traits > &re, regex_constants::match_flag_type flags=regex_constants::match_default)
 
template<typename BidirIt , typename CharT , typename Traits >
bool regex_match (BidirIt first, BidirIt last, match_results< BidirIt > &m, const basic_regex< CharT, Traits > &re, regex_constants::match_flag_type flags=regex_constants::match_default)
 Match of the entire [first, last) (Python re.fullmatch / std::regex_match).
 
template<typename CharT , typename Traits >
bool regex_match (const std::basic_string< CharT > &s, match_results< typename std::basic_string< CharT >::const_iterator > &m, const basic_regex< CharT, Traits > &re, regex_constants::match_flag_type flags=regex_constants::match_default)
 
template<typename CharT , typename Traits >
bool regex_match (const CharT *s, match_results< const CharT * > &m, const basic_regex< CharT, Traits > &re, regex_constants::match_flag_type flags=regex_constants::match_default)
 
template<typename BidirIt , typename CharT , typename Traits >
bool regex_match (BidirIt first, BidirIt last, const basic_regex< CharT, Traits > &re, regex_constants::match_flag_type flags=regex_constants::match_default)
 
template<typename CharT , typename Traits >
bool regex_match (const std::basic_string< CharT > &s, const basic_regex< CharT, Traits > &re, regex_constants::match_flag_type flags=regex_constants::match_default)
 
template<typename CharT , typename Traits >
bool regex_match (const CharT *s, const basic_regex< CharT, Traits > &re, regex_constants::match_flag_type flags=regex_constants::match_default)
 
template<typename CharT , typename Traits >
bool regex_search (const std::basic_string< CharT > &&, match_results< typename std::basic_string< CharT >::const_iterator > &, const basic_regex< CharT, Traits > &)=delete
 
template<typename CharT , typename Traits >
bool regex_search (const std::basic_string< CharT > &&, match_results< typename std::basic_string< CharT >::const_iterator > &, const basic_regex< CharT, Traits > &, regex_constants::match_flag_type)=delete
 
template<typename CharT , typename Traits >
bool regex_match (const std::basic_string< CharT > &&, match_results< typename std::basic_string< CharT >::const_iterator > &, const basic_regex< CharT, Traits > &)=delete
 
template<typename CharT , typename Traits >
bool regex_match (const std::basic_string< CharT > &&, match_results< typename std::basic_string< CharT >::const_iterator > &, const basic_regex< CharT, Traits > &, regex_constants::match_flag_type)=delete
 
template<typename CharT , typename Traits >
std::basic_string< CharT > regex_replace (const std::basic_string< CharT > &s, const basic_regex< CharT, Traits > &re, const std::basic_string< CharT > &fmt, regex_constants::match_flag_type flags=regex_constants::format_default)
 Replaces matches of re in s with the ECMAScript-formatted fmt.
 
template<typename CharT , typename Traits >
std::basic_string< CharT > regex_replace (const std::basic_string< CharT > &s, const basic_regex< CharT, Traits > &re, const CharT *fmt, regex_constants::match_flag_type flags=regex_constants::format_default)
 regex_replace overload for a C-string format.
 
template<typename OutputIt , typename BidirIt , typename CharT , typename Traits >
OutputIt regex_replace (OutputIt out, BidirIt first, BidirIt last, const basic_regex< CharT, Traits > &re, const std::basic_string< CharT > &fmt, regex_constants::match_flag_type flags=regex_constants::format_default)
 regex_replace writing to an output iterator (std parity).
 

Typedef Documentation

◆ cmatch

using real::compat::cmatch = typedef match_results<const char*>

Match over a C string.

Definition at line 304 of file regex_match.hpp.

◆ cregex_iterator

using real::compat::cregex_iterator = typedef regex_iterator<const char*>

Over a C string.

Definition at line 172 of file regex_iter.hpp.

◆ cregex_token_iterator

Over a C string.

Definition at line 369 of file regex_iter.hpp.

◆ csub_match

using real::compat::csub_match = typedef sub_match<const char*>

Sub-match over a C string.

Definition at line 299 of file regex_match.hpp.

◆ regex

using real::compat::regex = typedef basic_regex<char>

The char-path compat regex (real-eligible).

Definition at line 855 of file regex_core.hpp.

◆ smatch

using real::compat::smatch = typedef match_results<std::string::const_iterator>

Match over a std::string.

Definition at line 303 of file regex_match.hpp.

◆ sregex_iterator

using real::compat::sregex_iterator = typedef regex_iterator<std::string::const_iterator>

Over a std::string.

Definition at line 171 of file regex_iter.hpp.

◆ sregex_token_iterator

using real::compat::sregex_token_iterator = typedef regex_token_iterator<std::string::const_iterator>

Over a std::string.

Definition at line 368 of file regex_iter.hpp.

◆ ssub_match

using real::compat::ssub_match = typedef sub_match<std::string::const_iterator>

Sub-match over a std::string.

Definition at line 298 of file regex_match.hpp.

◆ wcmatch

using real::compat::wcmatch = typedef match_results<const wchar_t*>

Match over a wide C string (always std).

Definition at line 306 of file regex_match.hpp.

◆ wcregex_iterator

using real::compat::wcregex_iterator = typedef regex_iterator<const wchar_t*>

Over a wide C string (std).

Definition at line 174 of file regex_iter.hpp.

◆ wcregex_token_iterator

Over a wide C string (std).

Definition at line 371 of file regex_iter.hpp.

◆ wcsub_match

using real::compat::wcsub_match = typedef sub_match<const wchar_t*>

Sub-match over a wide C string.

Definition at line 301 of file regex_match.hpp.

◆ wregex

using real::compat::wregex = typedef basic_regex<wchar_t>

The wide compat regex (always the std backend).

Definition at line 856 of file regex_core.hpp.

◆ wsmatch

using real::compat::wsmatch = typedef match_results<std::wstring::const_iterator>

Match over a std::wstring (always std).

Definition at line 305 of file regex_match.hpp.

◆ wsregex_iterator

using real::compat::wsregex_iterator = typedef regex_iterator<std::wstring::const_iterator>

Over a std::wstring (std).

Definition at line 173 of file regex_iter.hpp.

◆ wsregex_token_iterator

using real::compat::wsregex_token_iterator = typedef regex_token_iterator<std::wstring::const_iterator>

Over a std::wstring (std).

Definition at line 370 of file regex_iter.hpp.

◆ wssub_match

using real::compat::wssub_match = typedef sub_match<std::wstring::const_iterator>

Sub-match over a std::wstring.

Definition at line 300 of file regex_match.hpp.

Enumeration Type Documentation

◆ policy

enum class real::compat::policy : std::uint8_t
strong

The drop-in policy for a pattern the linear engine cannot represent (backreferences, an unbounded lookaround, a POSIX class, …). strict (the default) rejects it, so every accepted pattern executes each regex_search/regex_match in time linear in the input — the ReDoS-safety guarantee (replace/iterate compose O(n) such operations: quadratic worst-case on any linear engine, never exponential); fallback delegates it to std::regex, which may accept it but forfeits the guarantee for that pattern.

Enumerator
strict 

Reject an ineligible pattern (throws regex_error with error_complexity). The default.

fallback 

Delegate an ineligible pattern to std::regex (backtracking — not ReDoS-safe).

Definition at line 147 of file regex_core.hpp.

Function Documentation

◆ operator==() [1/3]

template<typename BidirIt >
bool real::compat::operator== ( const sub_match< BidirIt > &  lhs,
const sub_match< BidirIt > &  rhs 
)

Definition at line 99 of file regex_match.hpp.

◆ operator==() [2/3]

template<typename BidirIt >
bool real::compat::operator== ( const sub_match< BidirIt > &  lhs,
const typename sub_match< BidirIt >::string_type &  rhs 
)

Equality against an owned string (the common std::sub_match comparison).

Definition at line 85 of file regex_match.hpp.

◆ operator==() [3/3]

template<typename BidirIt >
bool real::compat::operator== ( const typename sub_match< BidirIt >::string_type &  lhs,
const sub_match< BidirIt > &  rhs 
)

Definition at line 92 of file regex_match.hpp.

◆ regex_match() [1/8]

template<typename BidirIt , typename CharT , typename Traits >
bool real::compat::regex_match ( BidirIt  first,
BidirIt  last,
const basic_regex< CharT, Traits > &  re,
regex_constants::match_flag_type  flags = regex_constants::match_default 
)

Definition at line 516 of file regex_match.hpp.

◆ regex_match() [2/8]

template<typename BidirIt , typename CharT , typename Traits >
bool real::compat::regex_match ( BidirIt  first,
BidirIt  last,
match_results< BidirIt > &  m,
const basic_regex< CharT, Traits > &  re,
regex_constants::match_flag_type  flags = regex_constants::match_default 
)

Match of the entire [first, last) (Python re.fullmatch / std::regex_match).

Definition at line 488 of file regex_match.hpp.

◆ regex_match() [3/8]

template<typename CharT , typename Traits >
bool real::compat::regex_match ( const CharT *  s,
const basic_regex< CharT, Traits > &  re,
regex_constants::match_flag_type  flags = regex_constants::match_default 
)

Definition at line 533 of file regex_match.hpp.

◆ regex_match() [4/8]

template<typename CharT , typename Traits >
bool real::compat::regex_match ( const CharT *  s,
match_results< const CharT * > &  m,
const basic_regex< CharT, Traits > &  re,
regex_constants::match_flag_type  flags = regex_constants::match_default 
)

Definition at line 507 of file regex_match.hpp.

◆ regex_match() [5/8]

template<typename CharT , typename Traits >
bool real::compat::regex_match ( const std::basic_string< CharT > &&  ,
match_results< typename std::basic_string< CharT >::const_iterator > &  ,
const basic_regex< CharT, Traits > &   
)
delete

◆ regex_match() [6/8]

template<typename CharT , typename Traits >
bool real::compat::regex_match ( const std::basic_string< CharT > &&  ,
match_results< typename std::basic_string< CharT >::const_iterator > &  ,
const basic_regex< CharT, Traits > &  ,
regex_constants::match_flag_type   
)
delete

◆ regex_match() [7/8]

template<typename CharT , typename Traits >
bool real::compat::regex_match ( const std::basic_string< CharT > &  s,
const basic_regex< CharT, Traits > &  re,
regex_constants::match_flag_type  flags = regex_constants::match_default 
)

Definition at line 525 of file regex_match.hpp.

◆ regex_match() [8/8]

template<typename CharT , typename Traits >
bool real::compat::regex_match ( const std::basic_string< CharT > &  s,
match_results< typename std::basic_string< CharT >::const_iterator > &  m,
const basic_regex< CharT, Traits > &  re,
regex_constants::match_flag_type  flags = regex_constants::match_default 
)

Definition at line 498 of file regex_match.hpp.

◆ regex_replace() [1/3]

template<typename CharT , typename Traits >
std::basic_string< CharT > real::compat::regex_replace ( const std::basic_string< CharT > &  s,
const basic_regex< CharT, Traits > &  re,
const CharT *  fmt,
regex_constants::match_flag_type  flags = regex_constants::format_default 
)

regex_replace overload for a C-string format.

Definition at line 692 of file regex_match.hpp.

◆ regex_replace() [2/3]

template<typename CharT , typename Traits >
std::basic_string< CharT > real::compat::regex_replace ( const std::basic_string< CharT > &  s,
const basic_regex< CharT, Traits > &  re,
const std::basic_string< CharT > &  fmt,
regex_constants::match_flag_type  flags = regex_constants::format_default 
)

Replaces matches of re in s with the ECMAScript-formatted fmt.

Real-backed, non-nullable patterns run the substitution on real (linear, ReDoS-safe); the std backend and nullable real-backed patterns route to std::regex_replace (the empty-match traversal differs between Python real and ECMAScript, see basic_regex::nullable).

Definition at line 641 of file regex_match.hpp.

◆ regex_replace() [3/3]

template<typename OutputIt , typename BidirIt , typename CharT , typename Traits >
OutputIt real::compat::regex_replace ( OutputIt  out,
BidirIt  first,
BidirIt  last,
const basic_regex< CharT, Traits > &  re,
const std::basic_string< CharT > &  fmt,
regex_constants::match_flag_type  flags = regex_constants::format_default 
)

regex_replace writing to an output iterator (std parity).

Definition at line 702 of file regex_match.hpp.

◆ regex_search() [1/8]

template<typename BidirIt , typename CharT , typename Traits >
bool real::compat::regex_search ( BidirIt  first,
BidirIt  last,
const basic_regex< CharT, Traits > &  re,
regex_constants::match_flag_type  flags = regex_constants::match_default 
)

Definition at line 462 of file regex_match.hpp.

◆ regex_search() [2/8]

template<typename BidirIt , typename CharT , typename Traits >
bool real::compat::regex_search ( BidirIt  first,
BidirIt  last,
match_results< BidirIt > &  m,
const basic_regex< CharT, Traits > &  re,
regex_constants::match_flag_type  flags = regex_constants::match_default 
)

Leftmost search of [first, last) (Python re.search / std::regex_search).

Definition at line 434 of file regex_match.hpp.

◆ regex_search() [3/8]

template<typename CharT , typename Traits >
bool real::compat::regex_search ( const CharT *  s,
const basic_regex< CharT, Traits > &  re,
regex_constants::match_flag_type  flags = regex_constants::match_default 
)

Definition at line 479 of file regex_match.hpp.

◆ regex_search() [4/8]

template<typename CharT , typename Traits >
bool real::compat::regex_search ( const CharT *  s,
match_results< const CharT * > &  m,
const basic_regex< CharT, Traits > &  re,
regex_constants::match_flag_type  flags = regex_constants::match_default 
)

Definition at line 453 of file regex_match.hpp.

◆ regex_search() [5/8]

template<typename CharT , typename Traits >
bool real::compat::regex_search ( const std::basic_string< CharT > &&  ,
match_results< typename std::basic_string< CharT >::const_iterator > &  ,
const basic_regex< CharT, Traits > &   
)
delete

◆ regex_search() [6/8]

template<typename CharT , typename Traits >
bool real::compat::regex_search ( const std::basic_string< CharT > &&  ,
match_results< typename std::basic_string< CharT >::const_iterator > &  ,
const basic_regex< CharT, Traits > &  ,
regex_constants::match_flag_type   
)
delete

◆ regex_search() [7/8]

template<typename CharT , typename Traits >
bool real::compat::regex_search ( const std::basic_string< CharT > &  s,
const basic_regex< CharT, Traits > &  re,
regex_constants::match_flag_type  flags = regex_constants::match_default 
)

Definition at line 471 of file regex_match.hpp.

◆ regex_search() [8/8]

template<typename CharT , typename Traits >
bool real::compat::regex_search ( const std::basic_string< CharT > &  s,
match_results< typename std::basic_string< CharT >::const_iterator > &  m,
const basic_regex< CharT, Traits > &  re,
regex_constants::match_flag_type  flags = regex_constants::match_default 
)

Definition at line 444 of file regex_match.hpp.