Data & serialization

CRegex

Compile a regular expression, match whole strings, or collect all occurrences.

C++23 mc/CRegex.h
#include <mc/CRegex.h>

match() matches the entire input. Match outputs are appended; clear the destination first when replacing previous results.

Capture zero is the whole match. IgnoreCase enables case-insensitive matching. Invalid patterns throw CError.

Jump to a declaration · 11

CRegex

class CRegex

Types, constants & data

static constexpr uint32_t IgnoreCase = 0b01;
using Strings = CVector<cstr>;
using Range = std::pair<uint32_t, uint32_t>;
using Ranges = CVector<Range>;

Methods

CRegex

CRegex(const CRegex& r);
CRegex(CRegex&& r);
CRegex(const cstr& pattern, uint32_t flags = 0);
CRegex(const char* pattern, uint32_t flags = 0);

Compiles the pattern, optionally ignoring case. Invalid syntax raises CError; reuse the compiled object for repeated matches.

match

bool match(const char* text, Strings& matches) const;
bool match(const cstr& text, Strings& matches) const;
bool match(const char* text) const;
bool match(const cstr& text) const;

Requires the entire input to match the pattern. Capture overloads append the full match followed by capture groups to matches; a failed match leaves the output unchanged.

matchRanges

bool matchRanges(const char* text, Ranges& ranges) const;
bool matchRanges(const cstr& text, Ranges& ranges) const;

Matches the entire input and appends the full match and capture groups as (byte offset, byte length) pairs. These are lengths, not end offsets.

findAll

bool findAll(const char* text, CVector<Strings>& matches) const;
bool findAll(const cstr& text, CVector<Strings>& matches) const;

Finds successive matches anywhere in the input and appends one vector per match, containing the full match then capture groups. Returns whether at least one match was found.