|
REAL
Regular Expression Algorithmic Library — constexpr C++20 regex
|
Drop-in replacements for <regex>: basic_regex, regex_search / regex_match / regex_replace and the iterator types – backed by REAL's linear-time engine where it can serve the pattern, and by std::regex otherwise, never by a silent divergence.
More...
Namespaces | |
| namespace | detail |
| Backend routing and format expansion for the compat layer. Not a stable API. | |
| namespace | re2 |
| Drop-in replacement for RE2's API surface, on REAL's engine. | |
| 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) |
Equality with the string on the left, for std::sub_match parity. | |
| template<typename BidirIt > | |
| bool | operator== (const sub_match< BidirIt > &lhs, const sub_match< BidirIt > &rhs) |
| Equality between two sub-matches, by matched text. | |
| template<typename CharT , typename Traits , typename BidirIt > | |
| std::basic_ostream< CharT, Traits > & | operator<< (std::basic_ostream< CharT, Traits > &os, const sub_match< BidirIt > &m) |
Stream the matched text (std::sub_match parity). Found by ADL from std::cout << m[1]. Writes m.str() — empty when the group did not participate. | |
| 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) |
Leftmost search over a std::basic_string; forwards to the primary overload. | |
| 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) |
| Leftmost search over a C string; forwards to the primary overload. | |
| 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) |
Leftmost search over [first, last), without capturing; forwards to the primary overload. | |
| 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) |
Leftmost search over a std::basic_string, without capturing; forwards to the primary overload. | |
| 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) |
| Leftmost search over a C string, without capturing; forwards to the primary overload. | |
| 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) |
Whole-sequence match over a std::basic_string; forwards to the primary overload. | |
| 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) |
| Whole-sequence match over a C string; forwards to the primary overload. | |
| 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) |
Whole-sequence match over [first, last), without capturing; forwards to the primary overload. | |
| 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) |
Whole-sequence match over a std::basic_string, without capturing; forwards to the primary overload. | |
| 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) |
| Whole-sequence match over a C string, without capturing; forwards to the primary overload. | |
| 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). | |
| 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 CharT *fmt, regex_constants::match_flag_type flags=regex_constants::format_default) |
regex_replace to an output iterator with a C-string format (std parity). Mirrors the string+const CharT* overload — a bare literal "+" decays to const CharT*. | |
Drop-in replacements for <regex>: basic_regex, regex_search / regex_match / regex_replace and the iterator types – backed by REAL's linear-time engine where it can serve the pattern, and by std::regex otherwise, never by a silent divergence.
|
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 |
| fallback | Delegate an ineligible pattern to |
| std::basic_ostream< CharT, Traits > & real::compat::operator<< | ( | std::basic_ostream< CharT, Traits > & | os, |
| const sub_match< BidirIt > & | m | ||
| ) |
Stream the matched text (std::sub_match parity). Found by ADL from std::cout << m[1]. Writes m.str() — empty when the group did not participate.
| [in,out] | os | The stream. |
| [in] | m | The sub-match whose text is written. |
os, after writing. | bool real::compat::operator== | ( | const sub_match< BidirIt > & | lhs, |
| const sub_match< BidirIt > & | rhs | ||
| ) |
Equality between two sub-matches, by matched text.
| [in] | lhs | The left sub-match. |
| [in] | rhs | The right sub-match. |
true if they hold the same characters. | 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).
| [in] | lhs | The sub-match. |
| [in] | rhs | The string to compare its text against. |
true if they hold the same characters. | bool real::compat::operator== | ( | const typename sub_match< BidirIt >::string_type & | lhs, |
| const sub_match< BidirIt > & | rhs | ||
| ) |
Equality with the string on the left, for std::sub_match parity.
| [in] | lhs | The string. |
| [in] | rhs | The sub-match whose text is compared. |
true if they hold the same characters. | 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 |
||
| ) |
Whole-sequence match over [first, last), without capturing; forwards to the primary overload.
| [in] | first | Start of the sequence. |
| [in] | last | One past its end. |
| [in] | re | The pattern. |
| [in] | flags | Match flags. |
true if the whole sequence matched. | 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).
The other overloads forward here; those taking no \ref match_results skip capture filling.
| [in] | first | Start of the sequence that must match in full. |
| [in] | last | One past its end. |
| [out] | m | Result filled on success; ready-but-unmatched on failure. |
| [in] | re | The pattern. |
| [in] | flags | Match flags; a constraining one routes to std. |
true if the whole sequence matched. | bool real::compat::regex_match | ( | const CharT * | s, |
| const basic_regex< CharT, Traits > & | re, | ||
| regex_constants::match_flag_type | flags = regex_constants::match_default |
||
| ) |
Whole-sequence match over a C string, without capturing; forwards to the primary overload.
| [in] | s | The subject. |
| [in] | re | The pattern. |
| [in] | flags | Match flags. |
true if the whole sequence matched. | 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 |
||
| ) |
Whole-sequence match over a C string; forwards to the primary overload.
| [in] | s | The subject. |
| [out] | m | Result filled on success. |
| [in] | re | The pattern. |
| [in] | flags | Match flags. |
true if the whole sequence matched. | 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 |
||
| ) |
Whole-sequence match over a std::basic_string, without capturing; forwards to the primary overload.
| [in] | s | The subject. |
| [in] | re | The pattern. |
| [in] | flags | Match flags. |
true if the whole sequence matched. | 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 |
||
| ) |
Whole-sequence match over a std::basic_string; forwards to the primary overload.
| [in] | s | The subject. |
| [out] | m | Result filled on success. |
| [in] | re | The pattern. |
| [in] | flags | Match flags. |
true if the whole sequence matched. | 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.
| [in] | s | The subject. |
| [in] | re | The pattern whose matches are replaced. |
| [in] | fmt | ECMAScript replacement format, as a C string. |
| [in] | flags | Match/format flags. |
| 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).
The other overloads forward here.
| [in] | s | The subject. |
| [in] | re | The pattern whose matches are replaced. |
| [in] | fmt | ECMAScript replacement format; $N refers to a group, $& to the whole match. |
| [in] | flags | Match/format flags; one the real expander does not honor routes to std. |
| OutputIt real::compat::regex_replace | ( | OutputIt | out, |
| BidirIt | first, | ||
| BidirIt | last, | ||
| const basic_regex< CharT, Traits > & | re, | ||
| const CharT * | fmt, | ||
| regex_constants::match_flag_type | flags = regex_constants::format_default |
||
| ) |
regex_replace to an output iterator with a C-string format (std parity). Mirrors the string+const CharT* overload — a bare literal "+" decays to const CharT*.
| [out] | out | Destination the result is written through. |
| [in] | first | Start of the subject sequence. |
| [in] | last | One past its end. |
| [in] | re | The pattern whose matches are replaced. |
| [in] | fmt | ECMAScript replacement format, as a C string. |
| [in] | flags | Match/format flags. |
out advanced past what was written. | 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).
| [out] | out | Destination the result is written through. |
| [in] | first | Start of the subject sequence. |
| [in] | last | One past its end. |
| [in] | re | The pattern whose matches are replaced. |
| [in] | fmt | ECMAScript replacement format. |
| [in] | flags | Match/format flags. |
out advanced past what was written. | 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 |
||
| ) |
Leftmost search over [first, last), without capturing; forwards to the primary overload.
| [in] | first | Start of the sequence. |
| [in] | last | One past its end. |
| [in] | re | The pattern. |
| [in] | flags | Match flags. |
true if a match was found. | 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).
The other overloads forward here; those taking no \ref match_results skip capture filling.
| [in] | first | Start of the sequence to search. |
| [in] | last | One past its end. |
| [out] | m | Result filled on success; ready-but-unmatched on failure, as std leaves it. |
| [in] | re | The pattern. |
| [in] | flags | Match flags; a constraining one routes to std. |
true if a match was found. | bool real::compat::regex_search | ( | const CharT * | s, |
| const basic_regex< CharT, Traits > & | re, | ||
| regex_constants::match_flag_type | flags = regex_constants::match_default |
||
| ) |
Leftmost search over a C string, without capturing; forwards to the primary overload.
| [in] | s | The subject. |
| [in] | re | The pattern. |
| [in] | flags | Match flags. |
true if a match was found. | 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 |
||
| ) |
Leftmost search over a C string; forwards to the primary overload.
| [in] | s | The subject. |
| [out] | m | Result filled on success. |
| [in] | re | The pattern. |
| [in] | flags | Match flags. |
true if a match was found. | 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 |
||
| ) |
Leftmost search over a std::basic_string, without capturing; forwards to the primary overload.
| [in] | s | The subject. |
| [in] | re | The pattern. |
| [in] | flags | Match flags. |
true if a match was found. | 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 |
||
| ) |
Leftmost search over a std::basic_string; forwards to the primary overload.
| [in] | s | The subject. |
| [out] | m | Result filled on success. |
| [in] | re | The pattern. |
| [in] | flags | Match flags. |
true if a match was found.