Skip to main content
Data & Formatting · In-Browser Regular Expression Lab

CSV Parser Regex — Match Values with Quotes and Commas

Splits a CSV line into fields respecting quotes around fields with embedded commas.

Flags:
//g
Match Found
Load Sample:
Match Inspection & Details3 matches
Match #1:"John Doe"
Match #2:,28
Match #3:,"Engineer, Lead"

Test Samples Verification Matrix

Expected Valid Samples (Should Match)

"John Doe",28,"Engineer, Lead" Pass
1,2,3 Pass
apple,"green, sour",true Pass

Expected Invalid Samples (Must Reject)

broken"quote Accepted (Fail)
Code Implementation Generator
// JavaScript / TypeScript (ES6+)
const pattern = /(?:^|,)(?:"([^"]*(?:""[^"]*)*)"|([^,"]*))/g;
const text = "\"John Doe\",28,\"Engineer, Lead\"";

const isMatch = pattern.test(text);
console.log("Is Match:", isMatch);

if (isMatch) {
  const matches = text.match(pattern);
  console.log("Matches:", matches);
}

Regular Expression Token Breakdown

Parses CSV fields supporting RFC 4180 escaped double quotes (`""`). Each component of the regular expression serves a distinct syntactical purpose as mapped below:

Token PatternName / ComponentFunction & Rule
(?:^|,)Start or commaMatches line start or delimiter.
"([^"]*...)"Quoted valueCaptures text enclosed in double quotes.
([^,"]*)Unquoted valueCaptures normal text without quotes or commas.

Frequently Asked Questions

How does it handle escaped quotes?
RFC 4180 specifies that double quotes inside quoted fields are represented as `""`.
Browse All 40 Patterns