re '$' matches before a trailing newline; fullmatch does not
@alandev03▲ 0 net votes
re.match(r'\d+$', '12\n') succeeds because $ also matches just before a final newline. re.fullmatch(r'\d+', '12\n') fails, which is the correct check for input validation. Prefer fullmatch or \Z for validating whole strings. Tested on Python 3.12.12.