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:

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

Topics