テキスト
String Escape
テキストを文字列リテラル用にエスケープ(引用符、バックスラッシュ、制御文字)してコードに貼り付けられるようにする、またはアンエスケープして元に戻す。
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.
よくある質問
エスケープは正確には何をしますか?
引用符、バックスラッシュ、制御文字(改行やタブなど)を文字列リテラル内の有効なエスケープシーケンスに変換し、テキストをソースコードにそのまま貼り付けられるようにします。
引用符スタイルとunicodeオプションは何のためにありますか?
引用符スタイル(二重引用符、単一引用符、バックティック)は、文字列を壊さないためにどの文字をエスケープするかを決定し、\uXXXXオプションは非ASCII文字をそのままにする代わりにエスケープされたunicodeシーケンスに変換します。
貼り付けたテキストはサーバーに送信されますか?
いいえ、エスケープとそのエスケープ解除はJavaScriptを介してブラウザ内で完全に行われ、データはオンラインに送信されません。
テキストが複数の文脈を連続して通過する場合はどうすればいいですか?
正しい順序でエスケープする必要があります。まず内側の文脈(たとえばJSON)、次に外側の文脈(たとえばそのJSONが挿入されるシェルコマンド)です。順序を間違えたり階層を飛ばしたりすることが、「正しくエスケープしたはず」の文字列が実際には壊れてしまう典型的な原因です。
同じ引用符が文脈によってエスケープのされ方が違うのはなぜですか?
各文脈(JS文字列、JSON、シェル、正規表現)には、それぞれ固有の特殊文字セットと固有のエスケープ方法を持つ独自の構文があります。そのため正しいエスケープはテキスト自体ではなく、それがどこに挿入されるかによって決まります。