Split Text by Regex
About this tool
About Regex Splitter
Break a string into pieces wherever a pattern matches. Split on several delimiters at once (commas, semicolons and pipes with any spaces around them is the default), on blank lines, on sentence endings, before capital letters with a lookahead, or on any JavaScript regex you write. Switch to Plain text to split on an exact delimiter such as || without worrying about escaping. Decide what happens to the delimiters: remove them, keep each as its own item, attach it to the piece before (handy for keeping the full stop on each sentence) or to the piece after, or mimic JavaScript's String.split exactly, where capture groups in the pattern are inserted between pieces. Set Max splits to stop after a few cuts and keep the rest of the text together, like Python's maxsplit. Trim each piece and drop empty ones to clean up messy input, then copy the result as numbered lines, a JSON array or CSV. Splitting runs in your browser with a time limit, so nothing is uploaded and a runaway pattern can't hang the page.
Built and maintained by Abhi JainUpdated
How to Split Text with a Regex
- 1
Choose the delimiter
Under Split on pick Regex or Plain text, then type the delimiter pattern or text.
- 2
Paste the text
Paste into the Text panel or click Sample.
- 3
Set the options
Choose what happens to Delimiters, set Max splits, and tick Trim each piece or Remove empty pieces.
- 4
Copy the pieces
Pick Lines, JSON array or CSV as the Output, then copy or download.
Regex Splitter: questions and answers
How do I split a string by multiple delimiters?
Use a character class or alternation, such as [,;|] for comma, semicolon or pipe, or \s*[,;|]\s* to also swallow surrounding spaces. In JavaScript code this is text.split(/\s*[,;|]\s*/).
Why does String.split include extra items when my regex has brackets?
In JavaScript, if the split pattern contains capture groups, the captured text is inserted into the result between the pieces. Use (?:…) for grouping without capturing, or choose Insert capture groups here to see exactly what String.split returns.
How do I keep the delimiter when splitting?
Choose Keep as separate items, Attach to the piece before, or Attach to the piece after under Delimiters. In code you can split on a lookahead or lookbehind, for example /(?<=[.!?])\s+/ keeps the punctuation on each sentence.
What does Max splits do?
It limits how many times the text is cut; whatever is left stays in the last piece, like Python's str.split(sep, maxsplit). Note that JavaScript's own split(sep, limit) is different: it drops everything after the limit.
Related Tools
- Regex Match ExtractorExtract every regex match or capture group from text into a clean list, JSON array or CSV, with presets, de-duplication and sorting.
- Regex TesterTest JavaScript regular expressions live with highlighted matches, capture groups, replace preview and plain-English errors.
- Case ConverterConvert text to camelCase, snake_case, kebab-case, Title Case and 10 more at once.
- Whitespace Visualizer & CleanerReveal tabs, NBSP, zero-width characters and mixed line endings, then clean them.