On this page
re.PatternError
Prev: re.Pattern | Up: re | Next: re.purge
Rel: re.compile, re.error, re.escape, re.findall
Ref: docs.python.org โ re.PatternError
Tags: #public #python3 #stdlib #re
Import
import re
from re import PatternError
Signature & Overview
re.PatternError(msg, pattern=None, pos=None)
Exception raised for invalid regular expressions.
Methods & Attributes
PatternError.add_note(self, note, /)โ Add a note to the exceptionPatternError.with_traceback(self, tb, /)โ Set self.traceback to tb and return self.
Usage
import re
try:
re.compile(r"(unclosed")
except re.error as exc: # re.PatternError is the Python 3.13+ name (aliased to re.error)
assert "unterminated" in exc.msg
Gotchas
- Python 3.13+ canonical name for
re.error: Bothre.PatternErrorandre.errorrefer to the same exception class in 3.13+; catchre.errorif supporting Python 3.12 and earlier. - Diagnostic attributes: Inspect
exc.msg,exc.pattern,exc.pos,exc.lineno, andexc.colno.
REPL Inspect
from re import PatternError
help(PatternError)
Linked from
Related notes
- tuts/python3/stdlib_module/re/Pattern Linked here; links to this page; shared tags: #re, #stdlib
- tuts/python3/stdlib_module/re/purge Linked here; links to this page; shared tags: #re, #stdlib
- tuts/python3/stdlib_module/re Linked here; links to this page; shared tags: #stdlib
- tuts/python3/stdlib_module/re/compile Linked here; shared tags: #re, #stdlib
- tuts/python3/stdlib_module/re/error Linked here; shared tags: #re, #stdlib
- tuts/python3/stdlib_module/re/escape Linked here; shared tags: #re, #stdlib
- tuts/python3/stdlib_module/re/findall Linked here; shared tags: #re, #stdlib
- tuts/python3/stdlib_module/re/finditer shared tags: #re, #stdlib
- tuts/python3/stdlib_module/re/fullmatch shared tags: #re, #stdlib
- tuts/python3/stdlib_module/re/match shared tags: #re, #stdlib