Skip to content
Advertisement

Split using a bracket

How can I split a string using [ as the delimiter?

JavaScript

if I do

JavaScript

I get an error

Exception in thread “main” java.util.regex.PatternSyntaxException: Unclosed character class near index 1 [

Any help?

Advertisement

Answer

The [ is a reserved char in regex, you need to escape it,

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement