re.error
Prev: re.compile | Up: re | Next: re.escape
Rel: re.compile, re.escape, re.findall, re.finditer
Ref: docs.python.org โ re.error
Tags: #public #python3 #stdlib #re
Import
import re
from re import error
Signature & Overview
re.error(msg, pattern=None, pos=None)
Exception raised for invalid regular expressions.
Methods & Attributes
error.add_note(self, note, /)โ Add a note to the exceptionerror.with_traceback(self, tb, /)โ Set self.traceback to tb and return self.
Usage
import re
try:
re.compile(r"[a-z")
except re.error as exc:
assert exc.pos == 0
Gotchas
- Aliased to
re.PatternErrorin Python 3.13+: Catchingre.errorworks across all Python 3 versions. - Raised at compile time, not match failure: A pattern that simply doesn't match returns
Nonerather than raisingre.error.
REPL Inspect
from re import error
help(error)
Linked from
- tuts/python3/stdlib_module/re
- tuts/python3/stdlib_module/re/compile
- tuts/python3/stdlib_module/re/escape
- tuts/python3/stdlib_module/re/findall
- tuts/python3/stdlib_module/re/finditer
- tuts/python3/stdlib_module/re/fullmatch
- tuts/python3/stdlib_module/re/match
- tuts/python3/stdlib_module/re/Match_class
- tuts/python3/stdlib_module/re/Pattern
- tuts/python3/stdlib_module/re/PatternError
- tuts/python3/stdlib_module/re/purge
- tuts/python3/stdlib_module/re/RegexFlag
- tuts/python3/stdlib_module/re/search
- tuts/python3/stdlib_module/re/split
- tuts/python3/stdlib_module/re/sub
- tuts/python3/stdlib_module/re/subn
Related notes
- tuts/python3/stdlib_module/re/compile Linked here; links to this page; shared tags: #re, #stdlib
- tuts/python3/stdlib_module/re/escape Linked here; links to this page; shared tags: #re, #stdlib
- tuts/python3/stdlib_module/re/findall Linked here; links to this page; shared tags: #re, #stdlib
- tuts/python3/stdlib_module/re/finditer 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/fullmatch links to this page; shared tags: #re, #stdlib
- tuts/python3/stdlib_module/re/match links to this page; shared tags: #re, #stdlib
- tuts/python3/stdlib_module/re/Match_class links to this page; shared tags: #re, #stdlib
- tuts/python3/stdlib_module/re/Pattern links to this page; shared tags: #re, #stdlib
- tuts/python3/stdlib_module/re/PatternError links to this page; shared tags: #re, #stdlib