Matches a regexp to a string
This takes a regular expression object compiled previously with rex.new, and matches it against a target string.
If you are planning to do multiple matches against the same regular expression, it is faster to compile once only (ie. do rex.new once), and test multiple times.
However for once-off tests you can combine them both into the same line:
The third result returned is a table of capture patterns that have been matched.
Output from table.foreach:
This shows that the 2 capture patterns (the things in round brackets) have been captured in the table as index 1 and 2 (first and second pattern) and also under named indices "where" and "who" because we used named capture patterns in the regular expression.
See Also ...
re:exec - Matches a regexp to a string, returning offsets
Lua base functions
(Help topic: lua=re:match)
Enter a search string to find matching documentation.
Information and images on this site are licensed under the Creative Commons Attribution 3.0 Australia License unless stated otherwise.
Gammon Software support
Forum RSS feed ( https://gammon.com.au/rss/forum.xml )