Need a hint about an Re2 regex

Apparently I don’t understand regexes (or Re2 style regexes) well enough; I am using a Cloudflare firewall rule that matches URI ^/p/* , but it is also matching URIs like “/p-abcd/1234” and not just URIs like /p/1234 and I can’t figure out why.

Any regular expression wizards around? :slight_smile:

I’m not specifically familiar with Cloudflare’s firewall rules, but…

In RE2 and other similar regular expressions, * means “0 or more of the previous thing”. So ^/p/* is basically equivalent to ^/p and matches all paths that start with /p, whether or not the following character is a /.

Not sure what Cloudflare prefers, but you may want to switch it to ^/p/ or something similar. (That would not match the exact path /p, though.)

This topic was automatically closed after 30 days. New replies are no longer allowed.