could be that the EOF is appended from a filestream with std::getline, so that a file with a single char (f.e 'a') content is calling fstream.getline() returns a string with length() == 2 and it is {'a',EOF}.
You need to pop_back() that EOF before regex matches in full line range with "^\d$"