Solution to Regular Expression Matching

The key is to consider different situations!