Regex replace with reference to capture group in Python

s = re.sub(r"(\d+)", r"Number is: \1", text)

Note that it’s not possible to use r"\0" to reference the whole capture. r"\0" means character code 0, or null character.

Prerequisite

import re