Mindaugas Mindaugas - 2 months ago 20
JSON Question

Regex select text inside quotation marks into groups

I have a lot of lines in this format:

"1" "Melbourne is the capital of Australia." "0" "Canberra is the capital of Australia."

"2" "New York is the capital of Florida." "0" "Tallahassee is the capital of Florida."

"3" "Paris is the capital of France." "1" null


Expected result: {"id":\1,"statement":\2,"correct":\3,"additional":\4},

Answer

Since you know there are exactly 4 terms:

.*?(".*?").*?(".*?").*?(".*?").*?(null|(".*?").*

See demo

It's important to use reluctant quantifiers, which capture as little as possible.