On this page
  1. re.Match
  2. Import
  3. Signature & Overview
  4. Methods & Attributes
  5. Usage
  6. Gotchas
  7. REPL Inspect

re.Match

Prev: re.match | Up: re | Next: re.Pattern
Rel: re.compile, re.error, re.escape, re.findall
Ref: docs.python.org — re.Match
Tags: #public #python3 #stdlib #re


Import

import re
from re import Match

Signature & Overview

re.Match()

The result of re.match() and re.search().

Methods & Attributes

Usage

import re

m = re.search(r"(?P<user>\w+)@(?P<host>[\w.]+)", "Contact: ada@example.com")
assert isinstance(m, re.Match)
assert m.group(0) == "ada@example.com"
assert m.group("user") == "ada" and m.groupdict() == {"user": "ada", "host": "example.com"}
assert m.span() == (9, 24)

Gotchas

REPL Inspect

from re import Match
help(Match)

Linked from

Related notes