0

My first time, I try Lua script, I want to match on string (user-Agent), multiple substring to exclude them when it is match.

pattern string is User-Agent pattern, and the multiple string are google, safari and edge

 local m, err = ngx.re.match(ngx.req.get_headers()['User-Agent'], "(*google*|*safari*|*edge*)", "io")
    if not m
    then
      ..
    end

The problem User-Agent contain google, safari, edge string is still present on my request.

For instance User-Agent :

Mozilla/5.0 (**google**; CPU iPhone OS 14_4 like Mac OS X) 
Mozilla/5.0 (**safari**; CPU iPhone OS 15_1 like Mac OS X) 
Timescode_RESTClient **edge** alpha

I want to exclude them.

ezceeaaaa
  • 19
  • 5

1 Answers1

0

ngx.re.match uses PCRE regular expressions where * means roughly "zero or more repetitions of whatever is before it", so you must escape it: (\*google\*|\*safari\*|\*edge\*)

piotrp
  • 3,755
  • 1
  • 24
  • 26