How to use this tool
- Enter literal text.
- Select Update result to view the result.
- Check the method and assumptions below before using the result.
Input reference and sample values
Use the units and choices shown for each field. Sample values are provided for practice, not as recommendations.
| Input | Format and units | Sample |
|---|---|---|
| Literal text | Keep the structure and separators shown in the sample. Line breaks are retained in this input. | Price (USD): $19.99 [sale] |
Result for these sample inputs
Price \(USD\): \$19\.99 \[sale\]
Use as a standalone literal pattern. Escaping rules for character classes, replacement strings and embedded source-code strings differ.
Select Try the example in the form to load these values and calculate them again. This replaces the current form inputs. Compare the result with the method and worked explanation below.
The method, explained
Prefix regular-expression metacharacters with a backslash. Also escape / for slash-delimited JavaScript patterns, and represent line breaks as escaped characters.
Using literal text = Price (USD): $19.99 [sale], the result is Price \(USD\): \$19\.99 \[sale\]. Change these example inputs to match your task; use the method above to check each step.
What to keep in mind
This escapes a standalone pattern, not a character-class fragment or a replacement string. It does not execute a regular expression.
Common questions
Does it escape a replacement string too?
No. Replacement strings have different special sequences, such as $&. This output is for matching literal text in the pattern position.
Can I paste it directly inside a JavaScript string?
A source-code string may need another layer of backslash escaping. The output represents the regex pattern itself, not a quoted JavaScript string.
Methodology maintained by ClarityKit. How these tools are built and checked.