1

I am trying to filter out paths that start with certain string but do not have the "iframe" substring in it. Here is what seems to be working for me https://regex101.com/r/rIMFDP/1

^\/csr_and_sustainability_information\/(?!.*iframe)

but on amazon this regex doesnt work https://docs.aws.amazon.com/waf/latest/developerguide/waf-regex-pattern-set-creating.html

It states

AWS WAF supports the pattern syntax used by the PCRE library libpcre

I wonder if its possible to reproduce what I want within that standard

So I want select all routes starting with /csr_and_sustainability_information/ AND do not include "iframe" in the latter part of the URL

neuro
  • 14,948
  • 3
  • 36
  • 59
Hairi
  • 3,318
  • 2
  • 29
  • 68
  • I'd guess you're running into the latter notation `AWS WAF doesn't support all contructs of the library`. Likely lookaheads aren't supported. Can you have two constraints? – user3783243 Jun 23 '21 at 15:29

1 Answers1

2

You can use a POSIX compliant regex like

^/csr_and_sustainability_information/([^i]|i(i|f(i|r(i|a(i|mi))))*([^fi]|f([^ir]|r([^ai]|a([^im]|m[^ei])))))*(i(i|f(i|r(i|a(i|mi))))*(f(r?|ram?))?)?$

See this regex demo

The ([^i]|i(i|f(i|r(i|a(i|mi))))*([^fi]|f([^ir]|r([^ai]|a([^im]|m[^ei])))))*(i(i|f(i|r(i|a(i|mi))))*(f(r?|ram?))?)?$ part makes sure there is no iframe string after /csr_and_sustainability_information/.

Wiktor Stribiżew
  • 607,720
  • 39
  • 448
  • 563
  • Why no escape before the forward slash ? like this \/ . Is escape necessary? – Hairi Jun 24 '21 at 07:01
  • @Hairi No, it is only required when the forward slash is used as a regex delimiter. By itself, `/` is not any special regex metacharacter, so no need to escape it. You have no regex delimiters in the regex in the question. – Wiktor Stribiżew Jun 24 '21 at 07:16