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

re.escape

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


Import

import re
from re import escape

Signature & Overview

re.escape(pattern)

Escape special characters in a string.

Usage

import re

literal = "price is $9.99 (USD)"
pat = re.compile(re.escape(literal))
assert pat.search("Total: price is $9.99 (USD) today") is not None

Gotchas

REPL Inspect

from re import escape
help(escape)

Linked from

Related notes