Fix handling of EOF in regular expressions