This API provides PCRE regular expressions for those who needs more power in matching text. This API written in C and Lua.
Use regex.compile(pattern, options)
to compile a regex.
pattern
: The regex patternoptions
: regex modifiers as a string, eg "im"
"i"
: Case-insensitive search"m"
: Multiline search"s"
: Match all characters with dot (.
), including newlines.regex:cmatch(str, offset, options)
low-level matching function
str
: The string to match againstoffset
: Where to start matchingoptions
: A bit field of optionsregex.ANCHORED
: Only match from the start of the stringregex.ENDANCHORED
: Only match from the end of the stringregex.NOTBOL
: String is not beginning of lineregex.NOTEOL
: String is not the end of lineregex.NOTEMPTY
: Do not match an empty stringregex.NOTEMPTY_ATSTART
: Do not match empty string at the startNote: regex:cmatch()
returns wrong indexes (currently at version 2.0.2).
The end index returned by regex:cmatch()
is always off by 1 (-1 to get the actual end index).
All the functions below can be in 2 forms:
- regex:fn(...)
where regex
is the compiled regex instance
- regex.fn(pattern, ...)
where pattern
is a pattern string to be compiled and used directly.
We will only document the first form.
regex:match(str, offset, options)
high level matching function. This function accepts
the same arguments as regex:cmatch()
regex:gsub(str, replacement)
replaces matches in str
with replacement
.
Capture groups are identified with \0
to \9
, this might change in the future.