<highlight language="lua">
r:regex(string, pattern) -- Runs a regular expression match on a string, returning captures if matched:
-local matches = r:regex("foo bar baz", "foo (%w+) (%S*)")
+local matches = r:regex("foo bar baz", "foo (\w+) (\S*)")
if matches then
r:puts("The regex matched, and the last word captured ($2) was: " .. matches[2])
end
luaL_checktype(L, 2, LUA_TSTRING);
luaL_checktype(L, 3, LUA_TSTRING);
r = ap_lua_check_request_rec(L, 1);
- pattern = lua_tostring(L, 2);
- source = lua_tostring(L, 3);
+ source = lua_tostring(L, 2);
+ pattern = lua_tostring(L, 3);
flags = luaL_optinteger(L, 4, 0);
rv = ap_regcomp(®ex, pattern, flags);
}
lua_newtable(L);
- for (i = 0; i <= regex.re_nsub; i++) {
+ for (i = 0; i <= regex.re_nsub && i <= AP_MAX_REG_MATCH; i++) {
lua_pushinteger(L, i);
if (matches[i].rm_so >= 0 && matches[i].rm_eo >= 0)
lua_pushstring(L,