Skip to content
Advertisement

Regex split string in double quotes

I have the following string I need to split by double quotes. below is the sample string

JavaScript

When I try to split the string by double quotes, knowing that some quotes can be empty

I tried the following : String[] split = raw.split(""(\w\s+|\s+)"");

it is close but I seem to be missing something.

Advertisement

Answer

You can simply split it on \s*"\s* which means " preceded by or followed by zero or more whitespace character(s).

Demo:

JavaScript

Output:

JavaScript

ONLINE DEMO

Advertisement