Advertisement

Pattern library / Strings & Text

Regex to Match Simple CSV Lines

Matches a CSV row where values have no commas, quotes, or newlines. For quoted CSV with embedded commas, use a proper CSV parser.

The pattern
^[^,]+(,[^,]+)*$
Load this pattern into the tester →

How the pattern works

Test it: match & no-match examples

Every row is loaded straight into the tester — click Try to see the match live:

InputResultWhy
a,b,cMatchthree valuesTry →
singleMatchone valueTry →
a,,cNo matchempty value rejectedTry →
a,b,No matchtrailing comma rejectedTry →

Where to use it

JavaScript

const re = /^[^,]+(,[^,]+)*$/;
re.test('a,b,c');  // true

Python

import re, csv
re.match(r'^[^,]+(,[^,]+)*$', 'a,b,c')

Common mistakes

Test this pattern on your own data
Paste it into the free tester with your real strings — nothing leaves your browser.
Open the regex tester →

FAQ

For GA4-specific patterns, see the GA4 regex cheat sheet, the page path regex guide, the event filter regex guide, the GA4 regex match types, the custom channel grouping guide and RE2 vs PCRE. Browse the full regex pattern library.