A static site host lets you write redirect rules with wildcards. In a pattern, ? matches exactly one character (any character, including /), * matches any sequence of characters (including an empty one), and every other character matches only itself.
Write matchesRule(pattern, path) that returns true if the pattern matches the whole path, and false otherwise.
Input: pattern = "/user/*", path = "/user/42/settings" Output: true
* matches 42/settings.
Input: pattern = "/p?st", path = "/posts" Output: false
? matches one character, so the pattern only matches 5-character paths.
0 <= pattern.length, path.length <= 2000path has no ? or * characters.Run tries your code on the examples. Submit runs every test, including hidden edge cases, and solves the problem when they all pass.
Ctrl + Enter runs, Ctrl + Shift + Enter submits (⌘ on a Mac).
I'm here to help with #541 Redirect Rule With Wildcards. I give hints, never the solution, so you get to solve it yourself. Ask for a hint, select code to ask about it, or press Ask Tuto why on a failing test.
Your first 3 answers need no account. for free to keep asking.