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

re.subn

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


Import

import re
from re import subn

Signature & Overview

re.subn(pattern, repl, string, count=0, flags=0)

Return a 2-tuple containing (new_string, number).

Usage

import re

new_text, count = re.subn(r"\d+", "X", "a1 b2 c3")
assert new_text == "aX bX cX" and count == 3

Gotchas

REPL Inspect

from re import subn
help(subn)

Linked from

Related notes