From 14be51b1eca87dc1a97249d04984c2ce38926fa1 Mon Sep 17 00:00:00 2001 From: Guldoman Date: Sat, 28 May 2022 01:21:41 +0200 Subject: [PATCH] Make `regex.match` return all the results --- data/core/regex.lua | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/data/core/regex.lua b/data/core/regex.lua index 637d23fd..fa85d56c 100644 --- a/data/core/regex.lua +++ b/data/core/regex.lua @@ -5,8 +5,9 @@ regex.__index = function(table, key) return regex[key]; end regex.match = function(pattern_string, string, offset, options) local pattern = type(pattern_string) == "table" and pattern_string or regex.compile(pattern_string) - local s, e = regex.cmatch(pattern, string, offset or 1, options or 0) - return s, e and e - 1 + local res = { regex.cmatch(pattern, string, offset or 1, options or 0) } + res[2] = res[2] and res[2] - 1 + return table.unpack(res) end -- Will iterate back through any UTF-8 bytes so that we don't replace bits