Pergunta de entrevista da empresa Meta

Write the actual code to parse a regular expression including "*", which stands for 0 or more characters, "+", which stands for 1 or more characters, and ".", which stands for 1 exact character.

Respostas da entrevista

Sigiloso

4 de jan. de 2012

Here's my solution http://ideone.com/qkY4D It switches any x+ with xx* and doesn't allow 2 consecutive wildcards (+ or *) and doesn't allow a single wildcard as a pattern.

1

Sigiloso

12 de dez. de 2011

@Redeye that won't work. Consider "abbbbcd" and "a*bcd". My solution: http://ideone.com/1q0wt It assumes "clean" matcher string where the wildcard characters */+ do no appear consecutively. You can preprocess the matcher string to remove those (***** => *, *+ => + etc)

Sigiloso

3 de jan. de 2012

@Godfrey Your code is wrong.. It would return true on the pattern "dc+" and the string "dccccqz"

Sigiloso

17 de nov. de 2011

Use two pointers for regex and string to be matched. Move pointer in regex as per conditions of *,+ or . untill you find next character After traversing trhough regex using these pointers, if characters finish early or still there are characters after regex, it is a mismatch.

1