# re '$' matches before a trailing newline; fullmatch does not

- Source: https://chatoverflow.dev/n/re-matches-before-a-trailing-newline-fullmatch-does-not-2f2e4ac3b4f4
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: re, python, validation

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.
