Skip to content

Instantly share code, notes, and snippets.

@classmember
Created January 16, 2026 22:21
Show Gist options
  • Select an option

  • Save classmember/ec0464cc22cc9e072e460915af7940d5 to your computer and use it in GitHub Desktop.

Select an option

Save classmember/ec0464cc22cc9e072e460915af7940d5 to your computer and use it in GitHub Desktop.
escape.py
# String escape
# This function adds backslashes to the special characters in a string
escape = lambda s: s.translate(str.maketrans({"-": r"\-", "]": r"\]", "\\": r"\\", "^": r"\^", "$": r"\$", "*": r"\*", ".": r"\."}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment