Regex for Splitting a Comma-Separated String

Matches a comma optionally followed by whitespace, used to split CSV-like text into fields.

Published October 13, 2026

Matches a comma optionally followed by whitespace, used to split CSV-like text into fields.

Key points

  • This simple approach breaks down for CSV fields that contain commas inside quotes — use a proper CSV parser for real CSV files

Example

,\s*
More General articles