@@ -176,26 +176,26 @@ end
176
176
--- @return string[] ? arr
177
177
--- @return any err
178
178
function Regex :match (sbj , offset )
179
- local head , tail , err = self .p :match (sbj , offset or self .lastidx )
179
+ local heads , tails , err = self .p :match (sbj , offset or self .lastidx )
180
180
181
- if head then
181
+ if heads then
182
182
-- found
183
183
local arr = {}
184
- for i = 1 , # head do
185
- arr [i ] = sub (sbj , head [i ], tail [i ])
184
+ for i = 1 , # heads do
185
+ arr [i ] = sub (sbj , heads [i ], tails [i ])
186
186
end
187
187
188
188
-- updaet a last-index if global option is enabled
189
189
if self .global == true then
190
- self .lastidx = tail [1 ]
190
+ self .lastidx = tails [1 ]
191
191
end
192
192
return arr
193
+ elseif err then
194
+ return nil , err
193
195
elseif self .global then
194
196
-- reset a last-index to 0 if global option is enabled
195
197
self .lastidx = 0
196
198
end
197
-
198
- return nil , err
199
199
end
200
200
201
201
--- indexesof
@@ -291,10 +291,10 @@ Regex = require('metamodule').new(Regex)
291
291
--- @return any err
292
292
local function matches (sbj , pattern , flags , offset )
293
293
local re , err = Regex (pattern , flags )
294
- if err then
295
- return nil , err
294
+ if re then
295
+ return re : matches ( sbj , offset )
296
296
end
297
- return re : matches ( sbj , offset )
297
+ return nil , err
298
298
end
299
299
300
300
--- match
@@ -306,10 +306,10 @@ end
306
306
--- @return any err
307
307
local function match (sbj , pattern , flags , offset )
308
308
local re , err = Regex (pattern , flags )
309
- if err then
310
- return nil , err
309
+ if re then
310
+ return re : match ( sbj , offset )
311
311
end
312
- return re : match ( sbj , offset )
312
+ return nil , err
313
313
end
314
314
315
315
--- indexesof
@@ -321,10 +321,10 @@ end
321
321
--- @return any err
322
322
local function indexesof (sbj , pattern , flags , offset )
323
323
local re , err = Regex (pattern , flags )
324
- if err then
325
- return nil , err
324
+ if re then
325
+ return re : indexesof ( sbj , offset )
326
326
end
327
- return re : indexesof ( sbj , offset )
327
+ return nil , err
328
328
end
329
329
330
330
--- indexof
@@ -336,10 +336,10 @@ end
336
336
--- @return any err
337
337
local function indexof (sbj , pattern , flags , offset )
338
338
local re , err = Regex (pattern , flags )
339
- if err then
340
- return nil , err
339
+ if re then
340
+ return re : indexof ( sbj , offset )
341
341
end
342
- return re : indexof ( sbj , offset )
342
+ return nil , err
343
343
end
344
344
345
345
--- test
@@ -351,10 +351,10 @@ end
351
351
--- @return any err
352
352
local function test (sbj , pattern , flags , offset )
353
353
local re , err = Regex (pattern , flags )
354
- if err then
355
- return false , err
354
+ if re then
355
+ return re : test ( sbj , offset )
356
356
end
357
- return re : test ( sbj , offset )
357
+ return false , err
358
358
end
359
359
360
360
return {
0 commit comments