re:exec
Matches a regexp to a string, returning offsets
Prototype
start, end, offsets = re:exec (string, pos, flags)
Description
This takes a regular expression object compiled previously with rex.new, and matches it against a target string. It takes the same arguments are re:match, however the table returned as the 3rd result consists of pairs of offsets, rather than the strings themselves.
For example:
1 1
2 4
3 11
4 14
In this case we see that the first capture was from columns 1 to 4, and the second capture was from columns 11 to 14.
For example:
re = rex.new ("(.+) goes (.+)")
s, e, t = re:exec ("Nick goes East")
print (s, e) --> 1 14
table.foreach (t, print) --> see below
Output from table.foreach:1 1
2 4
3 11
4 14
In this case we see that the first capture was from columns 1 to 4, and the second capture was from columns 11 to 14.
Lua functions
- re:gmatch - Matches a regexp to a string, applying a function
- re:match - Matches a regexp to a string
- rex.flags - Returns a table of PCRE flags
- rex.new - Compiles a regular expression
Topics
- Lua LPEG library
- Lua PCRE regular expression functions
- Lua base functions
- Lua bc (big number) functions
- Lua bit manipulation functions
- Lua coroutine functions
- Lua debug functions
- Lua io functions
- Lua math functions
- Lua os functions
- Lua package functions
- Lua script extensions
- Lua string functions
- Lua syntax
- Lua table functions
- Lua utilities
- Scripting callbacks - plugins
- Scripting