Skip to main content

ClikaRT::regex::Regex

class

Header: ClikaRT/regex/regex.h

A compiled regular expression. Copyable is NOT provided (a compiled program is heavy); move it. Build one with Regex::compile.

Matching methods interpret both the pattern and the subject as bytes. Feed UTF-8 text (the default encoding); a byte-oriented match over UTF-8 is the common case. full_match requires the WHOLE subject to match; partial_match / search / find look for a match anywhere within it.

Nested types

NameDescription
OptionsCompile-time options (a subset of the engine's).

Types

enum Encoding

enum class Encoding : std::uint8_t

How the pattern and subject bytes are interpreted. The engine is byte-oriented; there is no wide/UTF-16 mode, and this only chooses how it reads 8-bit input.

EnumeratorDescription
Utf8UTF-8 (the default).
Latin1raw Latin-1 bytes

Declared in ClikaRT/regex/regex.h, line 47

Static member functions

compile(string_view, Options)

static Regex compile(std::string_view pattern, const Options& options)

Compile pattern with the given options. A malformed pattern raises ClikaRT::Error (InvalidArgument) carrying the engine's diagnostic. pattern is read during the call, not retained.

Declared in ClikaRT/regex/regex.h, line 66

compile(string_view)

static Regex compile(std::string_view pattern)

Compile pattern with default options. (An overload rather than a defaulted Options{} argument: a nested aggregate's default-member initializers aren't complete in a same-class default-argument context.)

Declared in ClikaRT/regex/regex.h, line 72

full_match(string_view, string_view)

static bool full_match(std::string_view text, std::string_view pattern)

Compile pattern and test it against text in one call. A malformed pattern raises ClikaRT::Error. Prefer compile + a member matcher when matching the same pattern repeatedly.

Declared in ClikaRT/regex/regex.h, line 135

partial_match(string_view, string_view)

static bool partial_match(std::string_view text, std::string_view pattern)

One-shot substring match of pattern in text; compiles per call, and hoist a Regex for a hot path.

Declared in ClikaRT/regex/regex.h, line 141

quote_meta()

static std::string quote_meta(std::string_view literal)

Escape the regex metacharacters in literal so the result matches literal verbatim.

Declared in ClikaRT/regex/regex.h, line 147

Member functions

Regex(Regex)

Regex(Regex&& other) noexcept

Move: transfers the compiled pattern.

Declared in ClikaRT/regex/regex.h, line 77

operator=(Regex)

Regex& operator=(Regex&& other) noexcept

Move-assign: transfers the compiled pattern.

Declared in ClikaRT/regex/regex.h, line 79

Regex(Regex)

Regex(const Regex&) =delete

Declared in ClikaRT/regex/regex.h, line 80

operator=(Regex)

Regex& operator=(const Regex&) =delete

Declared in ClikaRT/regex/regex.h, line 81

~Regex()

~Regex()

Releases the compiled pattern.

Declared in ClikaRT/regex/regex.h, line 83

pattern()

std::string pattern() const

The source pattern this was compiled from.

Declared in ClikaRT/regex/regex.h, line 86

num_capturing_groups()

int num_capturing_groups() const

Number of capturing groups in the pattern (group 0, the whole match, is not counted).

Declared in ClikaRT/regex/regex.h, line 89

named_groups()

std::map<std::string, int> named_groups() const

Named capture groups → their 1-based group index, for a pattern using (?P<name>...). Empty when the pattern declares none. Read the capture at groups[index - 1] from a *_groups match.

Declared in ClikaRT/regex/regex.h, line 93

full_match(string_view)

bool full_match(std::string_view text) const

True if the pattern matches the WHOLE text.

Declared in ClikaRT/regex/regex.h, line 99

partial_match(string_view)

bool partial_match(std::string_view text) const

True if the pattern matches ANY substring of text.

Declared in ClikaRT/regex/regex.h, line 101

full_match_groups()

std::optional<std::vector<std::string>> full_match_groups(std::string_view text) const

As full_match / partial_match, but on a match return capture groups 1..N (group 0, the whole match, is not included; an unmatched optional group yields ""). std::nullopt when there is no match.

Declared in ClikaRT/regex/regex.h, line 106

partial_match_groups()

std::optional<std::vector<std::string>> partial_match_groups(std::string_view text) const

Substring twin of full_match_groups; the pattern may match anywhere in text.

Declared in ClikaRT/regex/regex.h, line 109

find()

std::optional<std::pair<std::size_t, std::size_t>> find(
    std::string_view text,
    std::size_t start = 0
) const

Find the leftmost match at or after byte offset start (an unanchored search). Returns the match's [begin, end) byte offsets within text, or std::nullopt if there is none. Iterate by passing a previous match's end as the next start, the find-all form a tokenizer split needs.

Declared in ClikaRT/regex/regex.h, line 117

replace()

std::string replace(std::string_view text, std::string_view rewrite) const

Rewrite the FIRST match in text and return the result. If nothing matches, returns text unchanged.

Declared in ClikaRT/regex/regex.h, line 125

replace_all()

std::string replace_all(std::string_view text, std::string_view rewrite) const

Rewrite EVERY match in text and return the result.

Declared in ClikaRT/regex/regex.h, line 127