Add type check for regex matching variable