← Back to puzzles

002 Regular Expressions

Your challenge is to write your own miniature regular expression matcher. The matcher should handle regular expressions of the form a, where a can be any letter, and a* where a* means zero or more repetions of the same letter.

For example, given a regular expression x*yz, it should match the strings xxyz, xyz, yz, but not yyz.

Examples:

match("a", "a") -> true
match("b", "bb") -> false
match("a*a", "a") -> true
match("b*c", "bbbbc") -> true
match("xy*x", "xx") -> true
match("z*z", "zz") -> true
match("m*n", "mmmnm") -> false