Pregunta de entrevista de Meta

bool regular_expression_match(char* pattern, char* string) and pattern can contain kleene star.

Respuestas de entrevistas

Anónimo

30 de mar de 2013

Do you mean pattern can only normal characters or star? Will other special characters be included, e.g. '?', '+', '{}', '[]', etc.?

Anónimo

3 de may de 2013

bool rep(char* pattern, char* string) { if ((pattern[0] == 0) && (string[0] == 0)) return 1; if ((pattern[0] == 0) || (string[0] == 0)) return 0; if (pattern[1] == '*') { return (match(pattern, string) && (rep(pattern+2,string) || rep(pattern,string+1))); } else { return (match(pattern, string) && rep(pattern+1, string+1)); } } bool match(char* pattern, char* string) { if (*pattern == '.') return 1; return (*pattern == *string); }