🛠️ToolsShed

Échappement / Désé chappement de Chaînes

Échappez et désé chappez des chaînes pour JSON, JavaScript et HTML.

StringEscape.jsonDesc

StringEscape.cheatsheet

\\\
"\"
newline\n
tab\t
carriage return\r
backspace\b
form feed\f

Questions Fréquentes

Implémentation du Code

import json
import html
import re

text = 'Hello "world"\nLine 2 & <tag>'

# JSON string escaping
json_escaped = json.dumps(text)
print(json_escaped)
# '"Hello \"world\"\nLine 2 & <tag>"'

# Python repr (Python string literal escaping)
py_escaped = repr(text)
print(py_escaped)
# '\'Hello "world"\nLine 2 & <tag>\''

# HTML escaping
html_escaped = html.escape(text)
print(html_escaped)
# 'Hello &quot;world&quot;\nLine 2 &amp; &lt;tag&gt;'

# Regex escaping (escape metacharacters for use in pattern)
regex_escaped = re.escape("price: $4.99 (USD)")
print(regex_escaped)
# 'price:\ \$4\.99\ \(USD\)'

Comments & Feedback

Comments are powered by Giscus. Sign in with GitHub to leave a comment.