in reply to pcre regex

The lines from the text files may be ending with '\r\n' and '$' matches before an optional '\n'.
Opening the file in the '<:crlf' mode, or adding an optional "\r" into regex (/^\d{4}[A-Z0-9]\r?$/), may help.