Struct Regex¶
Defined in File Regex.hpp
Struct Documentation¶
-
struct Regex¶
Public Types
-
using value_type = char¶
-
using flag_type = RegexFlags¶
-
using replacer_type = RegexReplacer¶
Public Functions
-
explicit Regex(std::string_view regex, flag_type flags = flag_type::none())¶
Tries to compile a regex. The syntax follows the PCRE2 library.
- Parameters:
regex – the regex to compile, assumed to be valid UTF-8
flags – flags to configure the regex behaviour
- Throws:
RegexError – if the regex compilation was not successful
-
TriBool regex_match(std::string_view str) const noexcept¶
Similar to std::regex_match. Tries to match this regex against the whole string.
- Example:
Regex const r{"[0-9]+"}; assert(!r.regex_search("123456789a"));
- Parameters:
str – the string to match against, assumed to be valid UTF-8
- Returns:
true if the regex matched the whole string, false otherwise
-
TriBool regex_search(std::string_view str) const noexcept¶
Similar to std::regex_search. Tries to match this regex against a subsequence of str.
- Example:
Regex const r{"bra"}; assert(r.regex_search("abracadabra"));
- Parameters:
str – the string to match against, assumed to be valid UTF-8
- Returns:
true if the regex matched any substring in str, false otherwise
-
replacer_type make_replacer(std::string_view rewrite) const¶
Constructs a regex replacer for this regex by possibly compiling the rewrite string.
- Example:
Regex const r{"[0-9]+"}; RegexReplacer const repl = r.make_replacer("$0th"); std::string s = "Hello 13 World"; repl.regex_replace(s); assert(s == "Hello 13th World);
- Parameters:
rewrite – the string to replace all matches with, assumed to be valid UTF-8
- Throws:
RegexError – if an invalid rewrite string is encountered
-
using value_type = char¶