Regex Split Online — Split a String on a Pattern, Not a Character

//
Flags:
View:
10 items
Text to Split (Delimiter: /(\w+)@([\w.-]+)/)
Split Output
[0]"" (empty)0 chars
[1]hello5 chars
[2]example.com11 chars
[3] 1 chars
[4]test4 chars
[5]gmail.com9 chars
[6] 1 chars
[7]contact7 chars
[8]ashusevim.dev13 chars
[9]"" (empty)0 chars
Your regex and test data stay in your browser.
3 lines · 54 bytes
Support project

Regex Split Online — Split a String on a Pattern, Not a Character

Splitting on a literal comma breaks the moment a value contains a comma. Split on a pattern instead: see each resulting part, its index, and the exact delimiter that produced the boundary — before you write `split()` into a parser.

  • An empty capture group at the start of a string produces an empty first part — check index zero.
  • Use a limit to keep the remainder of the line in one piece.
  • Splitting on a capturing group in JavaScript keeps the separators in the result; that is a feature, not a bug.

This tool runs entirely in your browser. Your patterns and text are not uploaded, stored, or logged.

When a delimiter is not a delimiter

Real delimited text has structure: quoted fields, escaped separators, trailing newlines, repeated whitespace. `String.prototype.split` takes a pattern precisely so those cases are expressible, but the boundary behaviour is easy to get wrong by eye. Seeing the parts numbered, with empty strings made visible, turns a guess into a check.

The classic case is a CSV line where a quoted field contains the separator. Splitting on the comma silently produces the wrong column count; splitting on a pattern that understands quotes produces the right one, and the preview tells you which you have before the data is loaded anywhere.

Splitting log and config text

Line-oriented text rarely splits cleanly on `\n` alone: CRLF endings, blank lines at the end of a paste, and continuation lines all show up. Splitting on `\r?\n` and dropping empty parts is the pair of decisions that makes most log parsing work.

  • Whitespace runs: `/\s+/` collapses tabs, spaces and newlines into one boundary.
  • Word tokens: `/\W+/` keeps word characters together and discards punctuation.
  • Record blocks: split on a blank line with `/(?:\r?\n){2,}/`.

The limit argument, and why it matters

A limit stops splitting early and leaves the rest of the string in the final part. That is the correct behaviour when the first few fields identify a record and the remainder is free text — and the wrong behaviour when you silently discard the tail. Confirm the part count against the number of fields you expect.

Frequently asked questions

What is the difference between splitting on a string and on a regex?

A string delimiter matches one fixed sequence; a regex delimiter matches every string that fits a pattern, including optional whitespace and alternations. A regex also lets you keep separators in the result when the pattern contains a capture group.

Why does my split start with an empty string?

The input begins with the delimiter, so there is an empty part before the first boundary. Trim the input or filter empty parts, depending on which is semantically correct for your format.

Does this split large files in the cloud?

No. The text you paste is processed by JavaScript in your browser; nothing is uploaded, and no part of it is stored after you close the tab.

Related

Support the free tools