added lookahead regex and simplified slicing logic