النص
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.
مقالة عن هذه الأداة: الهروب بالأحرف: لماذا يختلف حسب السياق (JS وJSON والشِل والريجكس)
الأسئلة الشائعة
ما الذي تقوم الأداة بتهريبه بالضبط؟
تضيف الأداة رموز هروب لعلامات الاقتباس وللشرطة المائلة العكسية نفسها وأحرف التحكم مثل السطر الجديد والتبويب، بحيث يصبح النص جاهزًا للصق داخل حرفية نصية في الكود دون كسر الصياغة.
ما خيارات نمط علامات الاقتباس وهروب اليونيكود؟
يمكن اختيار علامات اقتباس مزدوجة أو مفردة أو خلفية بحيث تُهرَّب علامة الاقتباس المطابقة للنمط المختار فقط، كما يمكن تفعيل خيار تهريب الأحرف غير ASCII بصيغة \uXXXX عند الحاجة إلى نص يقتصر على أحرف ASCII.
ما الفرق بين وضعي الهروب وإلغاء الهروب، وهل النص يُرسل إلى خادم؟
وضع الهروب يحوّل نصًا خامًا إلى نص محمي برموز هروب، ووضع إلغاء الهروب يعكس العملية ليعيد النص الأصلي؛ وكلا الوضعين يعملان بالكامل داخل متصفحك عبر JavaScript دون إرسال أي بيانات إلى خادم.
ماذا أفعل إذا مرّ النص عبر عدة سياقات متتالية؟
يجب الهروب بالترتيب الصحيح: أولًا للسياق الداخلي (مثل JSON)، ثم للسياق الخارجي (مثل أمر شِل يُدرَج فيه ذلك JSON). ترتيب مقلوب أو تخطي أحد المستويين سبب شائع لتعطّل سلسلة "مُهرَّبة بشكل صحيح" عمليًا رغم ذلك.
لماذا تُهرَّب نفس علامة الاقتباس بطرق مختلفة في سياقات مختلفة؟
كل سياق (سلسلة JavaScript، JSON، شِل، تعبير نمطي) له صياغته الخاصة بمجموعة رموزه الخاصة وطريقته الخاصة في الهروب منها — لذا يعتمد الهروب الصحيح على المكان الذي يُدرَج فيه النص، لا على النص نفسه.