|
REAL
Regular Expression Algorithmic Library — constexpr C++20 regex
|
REAL's public API: real::regex, real::static_regex, real::flags and the match/iterator types built on them. More...
Namespaces | |
| namespace | compat |
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. | |
| namespace | detail |
| DFA construction internals: subset construction over a flattened NFA. Not a stable API. | |
Classes | |
| class | basic_match_iterator |
| Forward iterator over the non-overlapping matches in a text. More... | |
| class | basic_match_range |
A range of matches, returned by find_iter() and usable in range-for. More... | |
| class | basic_match_result |
| The result of a match attempt: success, spans and captures. More... | |
| class | basic_regex |
| A compiled regular expression, parameterized on its storage policy. More... | |
| class | dfa |
A multi-rule DFA: maximal-munch (dfa_mode::munch) or which-matched unanchored scan (dfa_mode::which_matched). More... | |
| class | dfa_error |
| Thrown when a pattern cannot be represented as a DFA. More... | |
| struct | dfa_match |
| The outcome of dfa::match — which rule won, and how many bytes it spans. More... | |
| struct | fixed_string |
| A fixed-size string usable as a non-type template parameter. More... | |
| class | regex_error |
The exception every rejected pattern throws: a message with the pattern offset it was found at, plus an error_kind a caller can branch on without parsing what. In a constexpr context (static_regex) reaching the throw is a compile-time error, the message appearing in the diagnostic trace. More... | |
| class | regex_set |
| Multi-pattern set: which patterns match the subject at least once. More... | |
Typedefs | |
| using | regex = basic_regex< detail::dynamic_storage > |
| The runtime-compiled regex type — the primary entry point. | |
| using | match_result = regex::result_type |
| The result type of the default, runtime-compiled real::regex. | |
| using | owning_match_result = regex::owning_result_type |
| What a single attempt on a TEMPORARY real::regex returns, owning its name context rather than borrowing it (see real::basic_regex::owning_result_type). | |
| template<fixed_string Pattern, flags F = flags::none> | |
| using | static_regex = basic_regex< detail::static_storage< Pattern, F > > |
| A fully compile-time regex. | |
Enumerations | |
| enum class | flags : std::uint16_t { none = 0 , icase = 1 , multiline = 2 , dotall = 4 , bytes = 8 , verbose = 16 , ecma = 32 , ascii = 64 , dollar_endonly = 128 , allow_raw_byte = 256 , ungreedy = 512 } |
Compilation flags, mirroring Python's re.I, re.M and re.S. More... | |
| enum class | match_semantics : std::uint8_t { first = 0 , longest = 1 } |
Which match a search returns among those starting at the leftmost position. Opt-in: first below is what a search uses unless asked otherwise. More... | |
| enum class | error_kind : std::uint8_t { syntax , unsupported } |
Whether a rejected pattern is malformed (syntax) or well formed but beyond REAL's linear engine (unsupported). More... | |
| enum class | dfa_mode : std::uint8_t { munch = 0 , which_matched = 1 } |
Build mode for real::dfa. More... | |
Functions | |
| constexpr flags | operator| (flags lhs, flags rhs) |
| Bitwise-OR of two flag sets. | |
| constexpr flags | operator& (flags lhs, flags rhs) |
| Bitwise-AND of two flag sets. | |
| constexpr flags | flags_without (flags value, flags removed) |
value with every flag in removed cleared – the (?flags-flags) removal. | |
| constexpr bool | has_flag (flags value, flags flag) |
Tests whether flag is set in value. | |
Variables | |
| constexpr std::size_t | npos {std::numeric_limits<std::size_t>::max()} |
| Sentinel for "no position" / unset capture slot (akin to std::string::npos). | |
REAL's public API: real::regex, real::static_regex, real::flags and the match/iterator types built on them.
| using real::match_result = typedef regex::result_type |
The result type of the default, runtime-compiled real::regex.
DERIVED, not re-spelled, and that is the whole point. Until v2026.8.8 this alias named basic_match_result<std::vector<std::size_t>> while the dynamic policy's slots are SBO-backed, so the type documented as "what `real::regex` returns" was not that type and declaring a variable with it did not compile. Nothing detected it because the alias RESTATED a type instead of asking for it; the restatement and the thing it restated were free to drift apart, and did, from the first commit. Deriving it makes that class of drift unrepresentable rather than merely detectable — the same reason real::regex and real::static_regex never drifted.
| using real::static_regex = typedef basic_regex<detail::static_storage<Pattern, F> > |
A fully compile-time regex.
The pattern is parsed, compiled and exactly sized at compile time; matching allocates nothing and also works in a constexpr context. An invalid pattern is a compile error.
| Pattern | The pattern, as a fixed_string literal. |
| F | Compilation flags. |
|
strong |
Build mode for real::dfa.
munch — maximal-munch at the cursor (lexer; default, SciLex). which_matched — unanchored multi-accept single-pass (Stage-2 RegexSet fused).
| Enumerator | |
|---|---|
| munch | One winner at the start of the subject (existing contract). |
| which_matched | Mid-stream restart; full accept-mask per state for which-matched. |
|
strong |
Whether a rejected pattern is malformed (syntax) or well formed but beyond REAL's linear engine (unsupported).
unsupported covers a backreference, a conditional, and a lookaround that is not bounded — the constructs a linear-time engine cannot represent at all. It is a stable, machine-readable classification the C ABI exposes, so a binding never has to grep regex_error::what.
There is no native escape hatch, by design — a real::regex is the linear engine or nothing. A caller who must run such a pattern anyway constructs a real::compat::regex from real/compat/std/regex.hpp with real::compat::policy::fallback, which delegates it to std::regex and forfeits the linear-time guarantee for that pattern only.
|
strong |
Compilation flags, mirroring Python's re.I, re.M and re.S.
Combinable with operator|. Case folding under flags::icase is Unicode in text mode and ASCII-only under flags::ascii (same split as the enumerator below and docs/divergences).
| Enumerator | |
|---|---|
| none | No flags. |
| icase | Case-insensitive (Unicode fold in text mode; ASCII under flags::ascii). |
| multiline |
|
| dotall |
|
| bytes | Binary mode: |
| verbose | Verbose mode ( |
| ecma | ECMAScript compatibility: |
| ascii | ASCII mode ( |
| dollar_endonly |
|
| allow_raw_byte | Permits |
| ungreedy | Ungreedy mode (RE2 |
|
strong |
Which match a search returns among those starting at the leftmost position. Opt-in: first below is what a search uses unless asked otherwise.
value with every flag in removed cleared – the (?flags-flags) removal.
There is no operator~ for flags on purpose: complementing a 16-bit enum would set every unassigned bit, and the result would be a flag set naming flags that do not exist. This states the whole operation instead. The intermediate width is unsigned, so the complement happens before the narrowing cast – doing it in std::uint16_t would drop flags::ungreedy (512) on a std::uint8_t-width intermediate, which is the exact bug the parser's own helper was written to avoid.
| [in] | value | The flag set to clear from. |
| [in] | removed | The flags to clear. |
value without removed. Tests whether flag is set in value.
| [in] | value | The flag set to query. |
| [in] | flag | The single flag to look for. |
true if flag is present in value. Bitwise-AND of two flag sets.
| [in] | lhs | First flag set. |
| [in] | rhs | Second flag set. |
lhs and rhs.