Regex¶
- class
This class is a C++ wrapper around the C library called SLRE (Super Lightweight Regular Expressions)
Example
Regex::Capure caps[3]; Regex reg("(..) (..) (..)"); bool success = reg.Match("test my regex", caps, 3); if (success) { String cap1 = reg.Value(caps[0]); }Pattern syntax
(?i)Must be at the beginning of the regex. Makes match case-insensitive^Match beginning of a buffer$Match end of a buffer()Grouping and substring capturing\sMatch whitespace\SMatch non-whitespace\dMatch decimal digit\nMatch new line character\rMatch line feed character\fMatch form feed character\vMatch vertical tab character\tMatch horizontal tab character\bMatch backspace character+Match one or more times (greedy)+?Match one or more times (non-greedy)*Match zero or more times (greedy)*?Match zero or more times (non-greedy)?Match zero or once (non-greedy)x|yMatch x or y (alternation operator)\metaMatch one of the meta character: ^$().[]*+?|\\xHHMatch byte with hex value 0xHH, e.g.[...]Match any character from set. Ranges like [a-z] are supported[^...]Match any character but ones from set
https://github.com/cesanta/slre
Public Functions
-
Regex::Regex(String pattern)¶ Create a regular expression object from a pattern string
-
bool
Regex::IsMatch(String matchStr)¶ Test if a string matches the regex pattern
- Return
trueon match,falseotherwise
-
bool
Regex::Match(String matchStr, Capture *captureArray, uint32_t capArraySize)¶ Get a the first capture group match from a string
The Regex class does not allocate any capure objects, so you must supply all needed objects for captures.
- Return
trueon match,falseotherwise- Parameters
matchStr-The string to match against the regex pattern
captureArray-A pointer to a array of Capture objects
capArraySize-The size of the provided capture array
-
String
Regex::Value(Capture &cap)¶ Return the string value from a match capture object