implemented regex and cleaned code thanks to swisskid