Wildcard matching decides whether an entire string is described by a pattern built from literal characters plus two wildcards: ? stands for exactly one character, and * stands for any run of characters, including none at all. This is the classic LeetCode 44 problem — the same style of matching a shell uses when you type *.txt. The catch is that * is greedy in theory but ambiguous in practice: a single * could stand for zero characters or twenty, and your matcher has to consider every split. The pattern must cover the whole string, not just a prefix.
wildcardMatch(s, pattern) // string, pattern -> boolean
Return true only if pattern matches all of s from start to end.
wildcardMatch('adceb', '*a*b'); // true — the two stars cover 'dce' and ''
wildcardMatch('acdcb', 'a*c?b'); // false — no split makes '?b' land on 'cb'
wildcardMatch('anything', '*'); // true — a single star matches any string
? matches exactly one character — never zero, never two. 'a?c' matches 'abc' but not 'ac'.* matches any sequence, including empty — '*' matches '', 'a', and 'abcdef' alike. Several *s in a row behave like one.'a*' matches 'abc', but 'a' does not.'' matches '' and nothing else, so a non-empty string needs a non-empty pattern.Unlock the solution & editor
Runnable editor + tests
Solve in the browser with instant Jest feedback.
Detailed solutions
Walkthroughs, edge cases, and complexity notes.
Multi-framework variants
React, Vue, Vanilla, Angular — same question, different stacks.