Regex Range Out of Order – Fix Invalid Character Range

Local only

Repair a JavaScript regex character class whose range endpoints are ordered incorrectly.

1 chars · 1 line

8 chars · 1 line

Pattern did not match the inputFlags: g

Regex range error

How to fix a regex character range that is out of order

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

What you can do here

  • JavaScript RegExp validation
  • Broken pattern preloaded
  • Corrected pattern comparison
  • Configurable regex flags
  • Browser-native error feedback
  • Browser-local processing

Steps

  1. Locate each hyphen inside the reported character class.
  2. Confirm whether it is intended as a range operator or a literal hyphen.
  3. Put range endpoints in ascending order, or escape/reposition the hyphen when it should be literal.

A hyphen may be syntax or data

[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.

Out-of-order regex range example

Reverse the endpoints so the range is valid.

Invalid pattern

[z-a]

Corrected pattern

[a-z]

Common questions

Frequently asked questions

Why is [z-a] invalid?

The range starts after its endpoint in character order, so JavaScript rejects it.

How do I match a literal hyphen?

Escape it as \- or place it where it is not interpreted as a range operator.

Is this the same as an unclosed class?

No. The brackets are balanced; the invalid syntax is the range inside them.

Debugging a specific Regex issue? Browse Regex troubleshooting.