On this page
  1. re.match
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

re.match

Prev: re.fullmatch | Up: re | Next: re.Match
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(pattern, string, flags=0)

Try to apply the pattern at the start of the string, returning a Match object, or None if no match was found.

Usage

import re

assert re.match(r"\d+", "42 apples") is not None
assert re.match(r"\d+", "apples 42") is None   # only checks the start of the string!

Gotchas

REPL Inspect

from re import match
help(match)

Linked from

Related notes