摘抄自<Beautiful Code> Chapter1:
Rob's 实现一个简单的正则表达式匹配程序。支持*^$.四个常规特殊字。
It is compact, elegant, efficient, and useful. It's one of the best examples of recursion that I have ever seen, and it shows the power of C pointers.
the regular expression code has also been an excellent way to illustrate algorithms, data structures, testing, performance enhancement, and other important topics.
Notice that advancing over the input string is done with a do-while loop, a comparatively unusual construct in C programs. The occurrence of a do-while instead of a while should always raise a question: why isn't the loop termination condition being tested at the beginning of the loop, before it's too late, rather than at the end after something has been done? But the test is correct here: since the * operator permits zero-length matches, we first have to check whether a null match is possible.
The order of tests in matchstar() is critical.
Feel the code yourself! Enjoy it.