There are two points to note:
The Meaning of "*" represents 0 or more repetitions of the characters preceding it. If "A *" stands for ' a ' followed by 0 or more characters ' a ';
Second, the use of C + + implementation of the following function is a string type, here by character processing when there are many inconvenience, can be converted to char * for processing.
Class Solution {public: bool Ismatchchar (const char *s, const char *p) {if (*p = = ') ' return *s = = ' + '; if (* (p + 1)! = ' * ') {if (*s! = ' && (*p = = *s | | *p = = '. ')) {return Ismatchchar (S + 1, p + 1);} Else{return false;}} Else{while (*s! = "&&" (*s = = *p | | *p = = '. ')) {if (Ismatchchar (s, p + 2)) return true;s++;} Return Ismatchchar (S, p + 2);}} BOOL IsMatch (string s, String p) { int lens = S.length (); int LENP = P.length () char* Schar = new Char[lens + 1];char* Pchar = new CHAR[LENP + 1];strcpy (Schar, S.c_str ()); strcpy (PC Har, P.c_str ()); Schar[lens] = ';p char[lenp] = ' Schar ', return Ismatchchar
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Regular Expression Matching