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\s
Match whitespace\S
Match non-whitespace\d
Match decimal digit\n
Match new line character\r
Match line feed character\f
Match form feed character\v
Match vertical tab character\t
Match horizontal tab character\b
Match 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|y
Match x or y (alternation operator)\meta
Match one of the meta character: ^$().[]*+?|\\xHH
Match 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
true
on match,false
otherwise
-
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
true
on match,false
otherwise- 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