Added recursive implementation which uses regexes