PATTERN PURIFIER // METASYMBOL ARCHITECTURE & REGEX SECURITY
Comprehensive defense against catastrophic backtracking, syntax exceptions, and Regular Expression Denial of Service (ReDoS).
The Danger of Unescaped User Input
When building search filters, highlight tools, or text replacers that incorporate user queries into a dynamic new RegExp(userInput), raw input poses critical vulnerabilities:
- Syntax Exceptions: Entering unbalanced brackets like
[or trailing quantifiers like+or?triggers immediateSyntaxError: Invalid regular expressionterminating script execution. - Unintended Wildcards: An unescaped dot
.matches any arbitrary character, silently causing searches forapi.v1to accidentally matchapixv1. - ReDoS Vulnerability: Malicious input containing nested quantifiers like
(a+)+$causes exponential backtracking (O(2ⁿ)), freezing the browser tab or Node.js event loop indefinitely.
Reserved Metasymbols Across Flavors
Standard regular expression engines reserve twelve core metasymbols that must be prefixed with a backslash escape:
- Core Metacharacters:
\ ^ $ . * + ? ( ) [ ] { } |. - Delimiter Slashes: In languages like JavaScript and PHP where expressions are enclosed in literal slashes
/pattern/g, the forward slash/must also be escaped as\/. - Python re.escape(): Python 3.7+ escapes only characters that have special meaning in regex, whereas earlier versions escaped all non-alphanumeric characters.
Airgap Zero-Log Privacy Architecture
Pattern Purifier executes sanitization purely in client-side memory using vanilla JavaScript string replacement algorithms. No user search strings, confidential regex patterns, or intellectual property are sent to any remote server.