If we wanted to backport this to 1.9, we could keep the regex's and do the check here instead of in the loop you're extracting below.