Register forum user name Search FAQ

re:exec

Summary

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.


See Also ...

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 base functions
Lua bc (big number) functions
Lua bit manipulation functions
Lua coroutine functions
Lua debug functions
Lua io functions
Lua LPEG library
Lua math functions
Lua os functions
Lua package functions
Lua PCRE regular expression functions
Lua script extensions
Lua string functions
Lua syntax
Lua table functions
Lua utilities
Scripting
Scripting callbacks - plugins

(Help topic: lua=re:exec)

Documentation contents page


Search ...

Enter a search string to find matching documentation.

Search for:   

Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.