check regex match before use