Teks
String Escape
Meng-escape teks menjadi literal string (tanda kutip, backslash, karakter kontrol) untuk ditempel ke kode, atau meng-unescape-nya kembali.
To put text containing quotes, line breaks, or backslashes inside a string literal in code, those characters need escaping — otherwise they'll end the string early or get misinterpreted. This tool escapes and unescapes text for a specific syntax.
How to use it
- Escape: paste text and pick a target context (a JS string, JSON, shell, etc.) and special characters get replaced with the matching escape sequences.
- Unescape: paste an already-escaped string to get the original text back.
- Different contexts escape the same character differently — make sure you've picked the mode matching where the text will actually be inserted.
Common uses
- Inserting multi-line text or text with quotes into a code variable without manually placing backslashes.
- Preparing a string for a shell command, where quotes and special characters can break execution.
- Unescaping a string copied from logs or a JSON response to read the original text.
Things to keep in mind
The same character (a double quote, for example) is escaped differently depending on context — a JS string, JSON, and a shell each have their own syntax and their own set of special characters.
Double-escaping (escaping already-escaped text) is a common mistake when passing data through multiple layers, like JSON nested inside a shell command.
Artikel tentang alat ini: String Escape: mengapa teks yang sama perlu di-escape secara berbeda
Pertanyaan yang sering diajukan
Apa sebenarnya yang dilakukan escaping?
Ini mengubah tanda kutip, garis miring terbalik, dan karakter kontrol (seperti jeda baris atau tab) menjadi urutan escape yang valid dalam literal string, sehingga teks dapat ditempel apa adanya ke kode sumber.
Untuk apa opsi gaya tanda kutip dan unicode?
Gaya tanda kutip (ganda, tunggal, atau backtick) menentukan karakter mana yang di-escape agar tidak merusak string, dan opsi \uXXXX mengonversi karakter non-ASCII menjadi urutan unicode yang di-escape alih-alih membiarkannya apa adanya.
Apakah teks yang ditempel dikirim ke server?
Tidak, escaping dan pembatalannya berjalan sepenuhnya di browser melalui JavaScript, tidak ada data yang dikirim secara online.
Bagaimana jika teks melewati beberapa konteks sekaligus?
Escaping harus dilakukan dalam urutan yang benar: pertama untuk konteks dalam (misalnya JSON), lalu untuk konteks luar (misalnya perintah shell tempat JSON tersebut disisipkan). Urutan yang tertukar atau satu level yang terlewat adalah penyebab umum mengapa string yang "sudah di-escape dengan benar" tetap rusak dalam praktiknya.
Mengapa tanda kutip yang sama di-escape berbeda pada konteks berbeda?
Setiap konteks (string JS, JSON, shell, regex) memiliki sintaks sendiri dengan kumpulan karakter khusus dan cara escaping-nya sendiri — sehingga escaping yang benar bergantung pada ke mana teks tersebut disisipkan, bukan pada teksnya sendiri.