Jane Street interview question

graph question with regular expressions