'.' matches any single character.
' * ' matches zero or more of the preceding element.
The matching should cover the entire input string (not partial).
The function prototype should be:
bool IsMatch (const char *s, const char *p)
Some Examples:
ismatch ("AA", "a") →false
ismatch ("AA", "AA") →true
IsMatch ("AAA", "AA") →false IsMatch (
"AA", "A *") →true ismatch
("AA", ". *") →true
ismatch ("AB", ". *") →true
ismatch ("AaB", "C*a*b") →true
This regular expression match, I set the IF statement according to different conditions, at the time of submission, because the. * Matching problem did not pass, now first put the code, and then modify
BOOL IsMatch (char* s,char* p) {
int i=0,j=0;
if (p[i]!= '. ') &&p[i]!=s[j]) {return
false;
}
i++;
j + +;
while (s[j]!= ' &&p[i]!= ') {
if (p[i]== '. ') P[i]==s[j]) {
i++;
j + +;
} else if (p[i]== ' * ') {
if (p[i-1]== '. ') {return
true;
} else if (p[i-1]== ' * ') {
//
}else{
if (S[j]==p[i]) {
j + +;
while (S[j]==s[j-1]) {
j + +;
}
}
i++
}
} else{return
false;
}
if (s[j]== ' ") {return
true;
} else{return
false;
}