Regex Escape
Escape regular-expression metacharacters so arbitrary text can be embedded safely in a RegExp.
Description
Escape regular-expression metacharacters so arbitrary text can be embedded safely in a RegExp.
Regex Escape: Escape regular-expression metacharacters so arbitrary text can be embedded safely in a RegExp.
When to use Regex Escape
Use this operation to escape literal text before inserting it into a regular-expression pattern for the intended regex engine.
- Pattern
- Text to escape.
How Regex Escape works
Escape regular-expression metacharacters so arbitrary text can be embedded safely in a RegExp. The tool evaluates the supplied inputs together and returns the named outputs below; it does not infer omitted operating conditions or change the units shown.1
- Escaped
- Text with every RegExp metacharacter backslash-escaped.
Limitations and assumptions
- Escaping rules differ among regex flavors and contexts such as character classes, replacement strings, delimiters, flags, and Unicode modes. Escaping a literal does not prevent denial-of-service from the surrounding pattern.
- Use finite inputs in the displayed units and preserve more precision than the final presentation requires. Independently verify safety-critical, financial, compliance, or production decisions.
Alternative or Complementary approaches
Use the target engine's documented literal-escape facility, anchor and bound patterns deliberately, and test adversarial input and runtime.
References
-
Regular expression — Wikipedia contributors
Similar or alternative tools
- Regular Expression Syntax Checker
Check whether a JavaScript regular expression and its flags compile. It does not run the expression against user text or claim to detect catastrophic backtracking.
- Battery Stored Energy Calculator
Convert a battery charge rating into stored energy, Wh = V * Ah, so packs of different voltages can be compared on equal footing.
- Hemoglobin From Hct Proxy
Approximate hemoglobin in g/dL from hematocrit percent with the clinical rule of three: hemoglobin is about one third of hematocrit. This screening proxy can be unreliable when red-cell size or hemoglobinization is abnormal.