This C++ project implements a simple regular expression engine for text manipulation.
This is a header-only project.
- Clone this repository and add the
./include/path to your compiler's include search path. - Include the main header file:
#include "regular_expression.hpp"Some advanced features have not been implemented yet, such as assertions and backreferences.
Free functions are available:
using namespace rais::regex;
// Match the whole target with the pattern:
auto [errc, match] = match("target", "pattern");
// Search for the first occurrence of the pattern in the target:
auto [errc, match] = search("target", "pattern");
// Search for all occurrences of the pattern in the target:
auto [errc, matches] = search_all("target", "pattern");
// Replace the specified count (default is unlimited) of matches of the pattern in the target:
std::string target = "target";
auto [errc, replaced_count] = replace(target, "pattern", "replacement" /*, maximum-replace-count */);
/*
where the type of
errc is rais::regex::error_category;
match is std::vector<string_view_like>;
matches is std::vector<std::vector<string_view_like>>;
maximum-replace-count is std::size_t
*/ - C++20 or later