Regex processor module


Port of gb_regex with several bugfixes applied. This is a simple regex library and is fast to perform.

Supported Matching:
^ - Beginning of string
$ - End of string
. - Match one (anything)
| - Branch (or)
() - Capturing group
[] - Any character included in set
[^] - Any character excluded from set
+ - One or more (greedy)
+? - One or more (non-greedy)
* - Zero or more (greedy)
*? - Zero or more (non-greedy)
? - Zero or once
[BACKSLASH]XX - Hex decimal digit (must be 2 digits)
[BACKSLASH]meta - Meta character
[BACKSLASH]s - Whitespace
[BACKSLASH]S - Not whitespace
[BACKSLASH]d - Digit
[BACKSLASH]D - Not digit
[BACKSLASH]a - Alphabetic character
[BACKSLASH]l - Lower case letter
[BACKSLASH]u - Upper case letter
[BACKSLASH]W - Not word
[BACKSLASH]x - Hex Digit
[BACKSLASH]p - Printable ASCII character
[BACKSLASH]n - New line
[BACKSLASH]r - Return carriage
[BACKSLASH]v - Vertical Tab
[BACKSLASH]f - Form feed


struct zpl_re
struct zpl_re_capture


using zpl_re = struct zpl_re
using zpl_re_capture = struct zpl_re_capture
using zplreError = enum zplreError


auto zpl_re_compile(zpl_re* re, zpl_allocator backing, char const* pattern, zpl_isize pattern_len) -> zplreError
Compile regex pattern.
auto zpl_re_compile_from_buffer(zpl_re* re, char const* pattern, zpl_isize pattern_len, void* buffer, zpl_isize buffer_len) -> zplreError
Compile regex pattern using a buffer.
auto zpl_re_destroy(zpl_re* re) -> void
Destroy regex object.
auto zpl_re_capture_count(zpl_re* re) -> zpl_isize
Retrieve number of retrievable captures.
auto zpl_re_match(zpl_re* re, char const* str, zpl_isize str_len, zpl_re_capture* captures, zpl_isize max_capture_count, zpl_isize* offset) -> zpl_b32
Match input string and output captures of the occurence.
auto zpl_re_match_all(zpl_re* re, char const* str, zpl_isize str_len, zpl_isize max_capture_count, zpl_re_capture** out_captures) -> zpl_b32
Match all occurences in an input string and output them into captures. Array of captures is allocated on the heap and needs to be freed afterwards.