Skip to content

Latest commit

 

History

History
22 lines (14 loc) · 543 Bytes

File metadata and controls

22 lines (14 loc) · 543 Bytes

assert_match

Asserts that a string-like value fully matches a regular expression.

The pattern must match the whole value, not just a substring. Pass a string pattern for readable failure output or a precompiled std::regex when the same expression is reused.

#include <regex>

#include <kaycxx/assert.hpp>

using namespace kaycxx::assert;

int main() {
    assert_match("user-42", "user-[0-9]+");

    auto id_pattern = std::regex{"item-[0-9]+"};
    assert_match("item-7", id_pattern);
}

Null C string pointers never match.