Regex Split Tester
Splitting a string on a pattern — whitespace, commas, any delimiter — is one of the most common regex jobs, and one where the result is easy to get wrong. This tester shows the exact array you would get from String.split, numbered so you can spot empty pieces, with options for a result limit and for keeping the delimiters via capture groups.
How to use the Regex Split Tester
Enter a split pattern as a regular expression, paste the text, and the parts appear as a numbered list with a live count and a JSON-array view you can copy. The default pattern \s*,\s* splits on commas while swallowing any surrounding spaces, so apple, banana ,cherry becomes three clean items rather than items padded with whitespace.
The limit field caps how many parts you get back, exactly like the second argument to String.split: a limit of 2 returns the first two pieces and discards the rest. Show empty parts controls whether zero-length results — which appear when delimiters are adjacent or sit at the start or end — are listed; turning it off filters them out, which is often what you want for clean tokenization. If your pattern contains capture groups, the captured delimiters are included in the output, mirroring JavaScript's behavior.
The split uses your browser's native engine, so the result is identical to running String.split in your own code, and nothing is sent anywhere.
Splitting strings with a regex
Splitting cuts a string into pieces wherever a delimiter appears, returning the text between the delimiters. Using a regular expression as the delimiter is far more powerful than splitting on a fixed character: a single pattern can absorb variable whitespace, accept several separators at once ([,;] for commas or semicolons), or split on structural boundaries like line breaks of any style (\r\n|\r|\n). This flexibility is why regex splitting shows up constantly in parsing CSV-like data, tokenizing input, and normalizing messy text.
The behavior has a few sharp edges worth understanding. Empty strings appear in the result when two delimiters are adjacent, or when the pattern matches at the very start or end of the input — splitting ",a,,b," on commas yields empty pieces at both ends and in the middle. That is correct and sometimes meaningful (a missing field), but for plain tokenization you usually filter the empties out, which is what the option here does. A limit argument stops the split early, returning only the first N pieces without merging the remainder.
Capture groups change the output in a useful way: when the split pattern contains a group, the captured text is spliced into the result between the surrounding pieces. This lets you split a string while keeping the delimiters — handy when you need to process the separators too, not just discard them. Seeing all of this laid out as a numbered list makes it obvious why a split produced the array it did, which is exactly the kind of thing that is hard to debug by staring at code.
Common use cases
- Parsing delimited data. Split lines on commas, tabs, or semicolons while trimming surrounding whitespace in one pattern.
- Tokenizing text. Break prose into words or segments on any run of non-word characters.
- Handling mixed line endings. Split a document into lines regardless of whether it uses LF, CR, or CRLF.
- Debugging a split. Confirm why your code's String.split produced empty entries or unexpected pieces.