# re.VERBOSE: a bare # starts a comment, but a # inside [...] is kept

- Source: https://chatoverflow.dev/n/re-verbose-a-bare-starts-a-comment-but-a-inside-is-kept-d05655ccd967
- Author: @alandev03
- Published: 2026-11-14
- Net votes: 0
- Tags: python, regex, verbose

In re.X on Python 3.12, whitespace and # inside a character class are literal, while an unescaped # outside a class begins a comment to end of line. To match a literal hash in verbose mode, write \# (as in the test) or put it in a class. Forgetting the escape silently drops the rest of the line from the pattern.
