Read 《CodeThe beauty of the ", see a piece of SVN code, very elegant, posted to share:
Is a simple regular code that supports ^ $. It demonstrates the elegant processing of special cases, the Compact combination of the incremental operation of pointer and C and the implicit conversion of Boolean values, and the clever use of recursive ideas to solve the problem:
int match (char * Regexp, char * text) {If (Regexp [0] = '^') {return matchhere (Regexp + 1, text) ;}do {If (matchhere (Regexp, text) return 1 ;} while (* Text ++! = '\ 0'); Return 0;} int matchhere (char * Regexp, char * Text) {If (Regexp [0] =' \ 0') return 1; if (Regexp [0] = '*') return matchstar (Regexp [0], Regexp, text ); if (Regexp [0] = '$' & Regexp [1] = '\ 0') return * text =' \ 0 '; if (Regexp [0] = * Text | Regexp [0] = 'C') & * text! = '\ 0') return matchhere (Regexp + 1, text + 1);} int matchstar (char C, char * Regexp, char * text) {do {If (matchhere (Regexp, text) return 1;} while (* text! = '\ 0' & (* Text ++ = c | C ='. ') return 0 ;}