check if regex matched before using result