changing method of checking if the regex matched, ditching unnecessary  array