Skip to content

Instantly share code, notes, and snippets.

@jamescherti
Last active December 25, 2022 22:03
Show Gist options
  • Select an option

  • Save jamescherti/981306ca16f92115a57796e1ae3d241d to your computer and use it in GitHub Desktop.

Select an option

Save jamescherti/981306ca16f92115a57796e1ae3d241d to your computer and use it in GitHub Desktop.
Escape all characters.
#!/usr/bin/env python
# License: MIT
# Author: James Cherti
# URL: https://gist.github.com/jamescherti/981306ca16f92115a57796e1ae3d241d
"""Escape all characters."""
import re
def escape_all(string: str):
"""Escape all characters."""
return re.sub(r'(.)', r'\\\1', string)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment