Script Valley
Regex: Actually Useful Patterns
Regex for Data Extraction and TransformationLesson 6.4

Regex to parse CSV and TSV data rows

CSV edge cases, quoted fields with commas, newlines in quoted fields, split vs regex, RFC 4180, Python csv module note

CSV Looks Simple Until It Is Not

CSV parsing

Splitting on commas breaks when fields contain quoted commas. A regex handles quoted fields correctly.

// Naive โ€” WRONG for quoted fields
'Alice,"New York, NY",30'.split(',')
// => ['Alice', '"New York', ' NY"', '30'] โ€” broken

When to Use a Library

For production CSV parsing, use a dedicated library: papaparse in JavaScript or Python's built-in csv module.

Up next

Building a regex-powered search and highlight function

Sign in to track progress

Regex to parse CSV and TSV data rows โ€” Regex for Data Extraction and Transformation โ€” Regex: Actually Useful Patterns โ€” Script Valley โ€” Script Valley