Passing null as input strings to substr() and preg_match() is deprecated in PHP 8.
Thus do not call substr() when input is null and pass an empty string instead of null to preg_match(). (Not calling preg_match() at all here would lead to Exception: Lexical error on line 1. Unrecognized text. ^).
Closes T15346