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

re.finditer

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


Import

import re
from re import finditer

Signature & Overview

re.finditer(pattern, string, flags=0)

Return an iterator over all non-overlapping matches in the string. For each match, the iterator returns a Match object.

Usage

import re

matches = [(m.group(), m.start(), m.end()) for m in re.finditer(r"\d+", "id=42 port=8080")]
assert matches == [("42", 3, 5), ("8080", 11, 15)]

Gotchas

REPL Inspect

from re import finditer
help(finditer)

Linked from

Related notes