Skip to content
OddsockLocal
Local
Source text

Formatting

4 wordsRuns in this browser. Nothing is uploaded.

How to use

  1. Paste the text to split.
  2. Set the pattern to whatever should be thrown away between pieces.
  3. Leave flags on gu unless you need a different set. g is added if it is missing.
  4. Read the JSON array of pieces, including empty strings.

What is Split by regex?

The splitter keeps what the pattern does not match. Pattern [,;]\s* against a; b,c returns the three strings a, b and c. The semicolons, the comma and the space after the semicolon are the separators, and they are not in the list. That is the opposite of the extractor, which would have returned the separators and dropped the words.

Read more

Flags default to gu, and g is added if you omit it so the split does not stop after the first separator. The result is JSON array, including empty strings when two separators sit next to each other or the text starts with a separator. Those empty entries are information: they mean a blank field, not a glitch to be trimmed automatically.

A pattern that matches an empty string can loop forever in some engines. JavaScript’s split has its own rules there. If the result looks longer than the text, the pattern is matching zero-width positions. Narrow it.

Use cases

  • A line uses both commas and semicolons, with optional spaces, and you want the fields a, b and c.
  • You need the pieces, not the matches, so the extractor’s list of separators is the wrong shape.
  • Two separators in a row should show up as an empty field rather than being silently closed up.
  • A one-off split is not worth a script, and the pattern is a bit more than a single comma.

Commas and semicolons, spaces optional

Text a; b,c. Pattern [,;]\s*. Flags gu.

[ "a", "b", "c" ]

Why use Oddsock

Empty fields stay in the array. Dropping them would hide a blank column in the original line.

Related tools

Using this tool

They matched the pattern, so they are separators. The extractor is the page that returns matches instead of the text between them.