Issue #16038: improve performance

Use strpos+substr instead of preg_match.