Skip to content

added the fifth param for ngx.re.find() #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 3 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 9 additions & 4 deletions lib/resty/core/regex.lua
Original file line number Diff line number Diff line change
Expand Up @@ -238,7 +238,8 @@ local function destroy_compiled_regex(compiled)
end


local function re_match_helper(subj, regex, opts, ctx, want_caps)
local function re_match_helper(subj, regex, opts, ctx, want_caps, nth)
if nth == nil then nth = 0 end
local flags = 0
local pcre_opts = 0
local pos
Expand Down Expand Up @@ -341,7 +342,11 @@ local function re_match_helper(subj, regex, opts, ctx, want_caps)
end

if not want_caps then
return compiled.captures[0] + 1, compiled.captures[1]
if n < rc and compiled.captures[n*2] >= 0 then
return compiled.captures[n*2] + 1, compiled.captures[n*2+1]
else
return nil, "the n-th is too large"
end
end

local res = collect_captures(compiled, rc, subj, flags)
Expand All @@ -359,8 +364,8 @@ function ngx.re.match(subj, regex, opts, ctx)
end


function ngx.re.find(subj, regex, opts, ctx)
return re_match_helper(subj, regex, opts, ctx, false)
function ngx.re.find(subj, regex, opts, ctx, nth)
return re_match_helper(subj, regex, opts, ctx, false, nth)
end


Expand Down