1 chars · 1 line
8 chars · 1 line
1 chars · 1 line
8 chars · 1 line
Regex range error
Inside a JavaScript character class, a hyphen can define a range. A descending range such as [z-a] is invalid and prevents the RegExp from compiling. This tool is free to use. No account or payment is required.
Last updated
[a-z] expresses an ordered range while [z-a] cannot. If you need the hyphen character itself, escape it or place it where it cannot be read as a range operator.
Reverse the endpoints so the range is valid.
[z-a][a-z]Common questions
The range starts after its endpoint in character order, so JavaScript rejects it.
Escape it as \- or place it where it is not interpreted as a range operator.
No. The brackets are balanced; the invalid syntax is the range inside them.
Debugging a specific Regex issue? Browse Regex troubleshooting.