I am trying to write a function bool match(char pattern[], char expresssion[])
which checks if the pattern matches the expression. If *
appears in the pattern, it can be matched with any string - the empty string as well. This is where my problem arises.
I am trying to cater for this star. My first idea was to check the next character that appears after the star and see whether it appears in the expression. If it appears at the n-th position, I move one-character in the pattern and start checking the expression further from the n-th position. However, it is not always obvious whether I should check my expression from the left or from the right. For example - if checked from the left, then this test would fail:
match("a*b", "ababab")
because only the first "b" would be "devoured" by the star. On the contrary, if I checked from the right, then this test would fail:
match("a*b*b*", "abbbbbbbba")
Could you give me a hint how I could deal with this star?