#460448 follow-up by chx: Replace advanced regex incompatible with PCRE < 7.2 with function-based approach.