Pregunta de entrevista de Meta

Write a basic Regex engine implementing the "." (any character) and "*" (previous rule, 0 to many). The function receives a string (letters only, no need for escaping) and a string pattern. It returns a bool whether the string matches the pattern. For example, the pattern "AB.*E" should match both "ABCDE" and "ABEEE".

Respuestas de entrevistas

Anónimo

22 dic 2015

Use recursion. Set 2 pointers at the beginning of both strings, advance each one by one. The trick is to look forward for a "*" and in this case fork to 2 recursive calls - one for a zero occurrences and one for multiple occurrences.

1

Anónimo

12 ene 2019

not to be cheeky but if they only want dot and star couldn't you just write a function whose body consisted solely of the line "return true"? dot star matches every possible string

Anónimo

9 nov 2016

Would this pattern(ab.*e) match str "abe"?