Regex in JavaScript/String.split() with regex

Split a string using a regex delimiter.

Section: JavaScript Regex APIs

String.split() with regex

javascript
javascript
csvLine.split(/\s*,\s*/)
Explanation

Removes optional whitespace around commas.

Learn the surrounding workflow

Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.

Related commands

Same sheet · prioritizing JavaScript Regex APIs
test() boolean match
Check whether a regex matches a string.
OpenIn sheetjavascriptsame section
exec() detailed match
Get captures and index information from a match.
OpenIn sheetjavascriptsame section
String.match()
Match against a string and return results.
OpenIn sheetjavascriptsame section
String.matchAll()
Iterate all matches with captures.
OpenIn sheetjavascriptsame section
String.replace()
Replace matched text using a regex.
OpenIn sheetjavascriptsame section
replace() callback
Compute replacements dynamically from captures.
OpenIn sheetjavascriptsame section