← All tools
// Text

Backslash Escape & Unescape online

Instantly add backslash escapes or unescape strings for code and configuration.

Backslash Add / Remove logo
by
CHUNKY
MUNSTER
// Output
Output will appear here...

How to Use the String Formatting Tool

  1. Paste your text into the input area.
  2. Pick a mode: Add backslashes (granular per-character toggles), Remove backslashes (drop every \x prefix), Escape for string literal (JSON.stringify), or Unescape string (JSON.parse).
  3. In Add mode, tick which characters to escape - single quotes, double quotes, backslashes, newlines, tabs.
  4. Click Run, then use Swap to feed the output back into the input for a round-trip check.

Backslash Escape & Unescape: add or strip backslash escapes from text instantly. Backslash escaping is the difference between a string that compiles and a syntax error. JSON requires " inside values to become \"; JavaScript and Python string literals need \n, \t, \r for control characters; Windows path doubling is required when paths live inside a string. This tool handles each of those cases without forcing you to escape the wrong things - pick exactly the character classes you want, or hand the whole string to JSON.stringify in one click.

Advanced String Literal Handling

Add and Remove modes run direct character-class regex passes - backslashes are processed first so they aren't double-escaped on a second pass. Escape for string literal hands the input to JSON.stringify and slices off the wrapping quotes, so the output is a fully valid JS or JSON string body. Unescape string goes through JSON.parse, so \uXXXX sequences and \n/\t/\r/\"/\\ are all decoded; if parse fails on malformed input, a fallback regex pass handles the common short forms. This regex literal escape functionality is essential for developers building dynamic patterns.

Frequently Asked Questions

What is the difference between Add backslashes and Escape for string literal?

Add backslashes lets you tick exactly which character classes get prefixed (quotes, newlines, tabs, backslashes). Escape for string literal runs JSON.stringify and returns the inner contents - a fully valid JS or JSON string body, including any required \uXXXX sequences.

Why do Windows paths break in JSON or JavaScript strings?

Backslash is the escape character, so C:\Users is parsed as C: followed by an escape of U. Each backslash must be doubled to C:\\Users\\name, which the Add backslashes mode produces in one click when the Backslashes box is ticked.

Does Unescape understand Unicode and hex escapes?

Unescape goes through JSON.parse, so \n, \t, \r, \", \\ and \uXXXX sequences are all decoded. Legacy octal escapes like \012 are not - JSON forbids them - and a fallback regex pass handles the most common short forms instead.

Will it touch backslashes that are already escaped?

In Add mode with the Backslashes option ticked, every literal backslash is doubled, so an existing \n becomes \\n. Untick Backslashes to leave existing escape sequences alone and only escape quotes, newlines or tabs.

For complex string manipulation in your code or config, bookmark this reliable Backslash Escape & Unescape tool.