
July 2, 2019. Cloudflare deploys one new firewall rule. Buried in it is a regular expression that backtracks catastrophically, and since the firewall runs on every single request before anything else, CPUs across the whole network jump to 100 percent. For 27 minutes a large slice of the web, Discord and Shopify included, just returns errors. The lesson: match in linear time, never explode. Build the matcher that scans once.
Objective
Match text against a pattern where * means any run of characters, in a single linear scan.
Steps
$ wildcard_match("a*c", "abc")
1
$ wildcard_match("a*c", "abd")
0
$ wildcard_match("*=*", "key=val")
1
Expected files
Allowed functions
None. Write every helper yourself.
Loading solutions...