Skip to content

re invalid escape sequence isn't: \( and \) #137835

@ethanfurman

Description

@ethanfurman

Bug report

Bug description:

According to the docs:

(...)
Matches whatever regular expression is inside the parentheses, and indicates the start and end of a group; the contents of a group can be retrieved after a match has been performed, and can be matched later in the string with the \number special sequence, described below. To match the literals '(' or ')', use \( or \), or enclose them inside a character class: [(], [)].

However, when I try to use the \( and \) literals, I get:

SyntaxWarning: invalid escape sequence '\('
  return bool(re.match('^Custom\([^)]*\)$', text))

Note that using the character classes [(] and [)] does work, but in my opinion re strings are hard enough to read as-is. ;-)

Tested on 3.12 and 3.13.

CPython versions tested on:

3.13

Operating systems tested on:

Linux

Metadata

Metadata

Assignees

No one assigned

    Labels

    stdlibPython modules in the Lib dirtopic-regextype-bugAn unexpected behavior, bug, or error

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions