Regex Unclosed Character Class – Fix Unterminated [ ]

Local only

Find a JavaScript regex character class that begins with [ but never reaches a matching ].

3 chars · 1 line

8 chars · 1 line

Pattern did not match the inputFlags: g

Regex character class error

How to fix an unclosed regex character class

A [ starts a character class in JavaScript regex syntax. If the pattern ends before a matching ], RegExp construction fails with an unterminated character class error. 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. Find the opening [ named by the failing pattern area.
  2. Check whether a literal ] was escaped or a closing ] is missing.
  3. Add the matching ] and then validate any ranges inside the class.

Character classes have their own parsing rules

Inside a class, characters such as - and ^ can change meaning. First close the class correctly; only then diagnose range ordering or escaping inside it.

Unclosed character class example

Close the bracket around the intended alternatives.

Invalid pattern

[abc

Corrected pattern

[abc]

Common questions

Frequently asked questions

What does [abc] match?

It matches one character that is a, b, or c.

Does a literal [ need escaping?

Usually yes when you want the bracket itself instead of starting a character class.

Can ] appear inside a character class?

Yes, but placement and escaping matter. The class still needs an unambiguous closing bracket.

Debugging a specific Regex issue? Browse Regex troubleshooting.