Regexdrill

Level 4: Extraction and cleanup Exercise 52 of 70 Free

CSV fields with quotes

A regex exercise from Regexdrill. Solve it with a pattern box with live highlighting in your browser, checked against hidden test strings, and it is checked the moment you submit.

The task

Match every field of a comma-separated line. A field is either text wrapped in double quotes, which may contain commas (the quotes are part of the match), or a run of one or more characters other than commas and quotes. Empty fields are skipped. The whole match is compared.

What this exercise teaches

"[^"]*"|[^,"]+ tries the quoted field first, so a comma inside quotes stays inside the field. A greedy ".*" would run from the first quote on the line to the last one.

A hint if you get stuck

Put the quoted form first in the alternation and use a negated class inside the quotes, so the match stops at the first closing quote.

Try it now, free, no account needed

Every exercise on Regexdrill is free to try. Open it on the practice page, solve it, and get instant feedback with a hint. A free account adds the worked solution; Pro adds timed mode and the certificate.

Open this exercise

More exercises in Extraction and cleanup