ToolActToolAct

Remove Newlines Tool

Quickly remove line breaks from text with multiple processing modes

Input
Characters: 0
Lines: 0
Output
Characters: 0
Lines: 0

Select Processing Mode

What is Remove Newlines?

Remove newlines is the process of handling or deleting line break characters in text. Line breaks are special characters that control text display formatting. Different systems use different line break standards: Windows uses CRLF (\r\n), Unix/Linux uses LF (\n), and early Mac used CR (\r). This tool supports processing all common line break formats, providing four processing modes: remove all newlines, newlines to spaces, remove empty lines, and merge empty lines to meet various text organization needs. When removing newlines, it matters whether paragraphs should be joined with spaces or collapsed directly. CSV snippets, logs, copied articles, prompts, code fragments, and form text may each need different handling. Removing line breaks blindly can merge words, destroy list structure, change meaning, or make structured data harder to read. Before sending important text onward, compare the result with the original and decide whether empty lines, indentation, and paragraph boundaries should be preserved.

How to Use

How to use

  1. Enter or paste the text you want to process in the left input box
  2. Select a processing mode (Remove All Newlines, Newlines to Spaces, etc.)
  3. The result will automatically appear on the right side with real-time preview
  4. Click 'Copy' to copy the result, or click 'Swap' to use the result as input for further processing

Text Cleanup Tips

  • Choose Newlines to Spaces when words should stay separated; removing all newlines can accidentally join words or fields together.
  • For structured data such as CSV, code, or addresses, preview the result before copying because line breaks may carry meaning.

Use Cases

Flatten copied text into one lineUse remove-all mode when pasted text from PDFs, emails, terminals, or wrapped web pages must become a continuous string. Character and line counts on both sides make the transformation easy to verify. The output is the kind of single-line blob that fits cleanly into a JSON string, a SQL VALUES row, or a .env value.
Convert line breaks into spacesThe to-space mode preserves word separation while removing hard line breaks, which is useful for paragraphs copied from narrow columns, translated text, CSV notes, or prompts that should become a single readable paragraph. The output keeps punctuation and capitalization intact while the line-break boundary becomes a single space.
Clean blank lines without destroying structureRemove-empty mode deletes only blank lines, while merge-empty normalizes repeated line breaks into a single newline. These modes are useful for tidying lists, logs, outlines, and pasted notes where line structure still matters. Choose merge-empty when paragraph spacing carries meaning and remove-empty when only the content matters.
Normalize CRLF, LF, and CR line endingsWhen text arrives from Windows, macOS, or older sources, switch the mode that targets only the carriage return or line feed byte. The matching regex \r?\n\s* cleanly handles mixed CRLF (Windows), LF (Unix/Linux), and lone CR (classic Mac) inputs in a single pass. This avoids touching accidental spaces inside paragraphs while still fixing mixed-endings that break shell scripts, git diffs, or Markdown tables.
Paste into JSON strings, SQL VALUES, or env filesFlatten copied notes before dropping them into a JSON literal, a SQL VALUES list, or a .env entry where raw newlines would break parsing. The character and line counts on both panels help confirm the result is one clean line, then quote or escape it appropriately for the target format. The same flat value can then be re-formatted with \n escapes for JSON or kept literal for tools that accept multi-line inputs.

Technical Principle

Each mode is one call to String.prototype.replace with a global regular expression. Remove-all uses /[\r\n]+/g and replaces with the empty string; newlines-to-spaces uses /[\r\n]+/g and replaces with a single ' '; merge-empty uses /(\r?\n){2,}/g and replaces with '\n\n' to collapse three or more line breaks into one blank line; remove-empty splits on /\r?\n/, filters out trimmed-empty entries, and rejoins on '\n'. The character-class form [\r\n] is deliberate because the three classic line endings — CRLF (\r\n, Windows since DOS), LF (\n, Unix and modern macOS), and lone CR (\r, classic Mac OS up to System 9) — must all be absorbed even when they appear mixed in the same file (a common artefact of copy-pasting between platforms or editing a Unix file in Notepad). Two additional Unicode break points exist but are rare in practice: U+2028 LINE SEPARATOR and U+2029 PARAGRAPH SEPARATOR, defined by the Unicode UAX #14 line-breaking algorithm and recognised by JavaScript string literals since ES2019. The tool currently treats them as ordinary characters, which matches what most users expect when they paste from a chat app. The BOM (U+FEFF) at the start of a UTF-8 file is also passed through unchanged — strip it separately if the downstream parser is strict. Real-time updating is driven by a React useState/useMemo pair: a controlled textarea writes input, the memo recomputes the result on every keystroke, and React's reconciliation only repaints the output panel. Because regex replacement on strings up to a few hundred KB completes in under a millisecond on a modern V8, no debouncing is needed; for multi-megabyte inputs the cost is still well under the 16 ms frame budget at 60 Hz.

  • Remove-all: text.replace(/[\r\n]+/g, '') — collapses runs of line breaks into nothing, fine for JSON string literals and .env values
  • Newlines-to-spaces: text.replace(/[\r\n]+/g, ' ') — preserves word boundaries from wrapped paragraphs without doubling spaces
  • Merge-empty: text.replace(/(\r?\n){2,}/g, '\n\n') — squashes runs of blank lines down to a single blank, preserving paragraph rhythm
  • Remove-empty: split(/\r?\n/).filter(l => l.trim() !== '').join('\n') — keeps content lines and normalises endings to LF in one pass
  • Line-ending zoo: CRLF (Windows \r\n, originally typewriter carriage-return + line-feed), LF (Unix \n since the 1970s), CR (classic Mac up to System 9) — the [\r\n] character class catches all three; Unicode U+2028 and U+2029 from UAX #14 are recognised by ES2019 string literals but rare in user input
  • BOM (U+FEFF) at file start is left untouched — strip it with text.replace(/^\uFEFF/, '') if the next stage is a strict JSON or CSV parser
  • Git's core.autocrlf=true normalises CRLF↔LF on checkout — use this tool when the file already arrived on your machine with the wrong endings and Git did not catch it

Examples

PDF Copied Text Organization

Original: Thi s is
from PDF
copied
content
After: ThisisfromPDFcopiedcontent

Code Compression Example

Original: function hello() {
  return 'world';
}
Compressed: function hello(){return 'world';}

Article Paragraph Organization

Remove extra blank lines while preserving paragraph spacing for neat and standardized article formatting

FAQ

What kinds of newlines are removed?

All three line-ending conventions: LF (\n, Unix/macOS), CRLF (\r\n, Windows), and CR (\r, classic Mac). The output is a single line. Optionally also remove or normalize tabs, multiple spaces, and other whitespace characters.

Will it preserve paragraph spacing?

Toggle 'collapse to single space' to replace each newline with a space. Toggle 'remove entirely' to concatenate without anything. For paragraphs with blank lines, you can also choose to keep paragraph breaks (one newline) and remove only the line wraps inside paragraphs - common when un-wrapping pasted PDF text.

Why does my pasted text have visible breaks I can't remove?

Probably soft line breaks or invisible separators like U+2028 (LINE SEPARATOR) or U+0085 (NEL). Toggle 'remove all whitespace separators' (a Unicode-aware option) instead of plain newline removal. Some PDF copies include zero-width spaces too - turn on 'remove invisible characters'.

How is this different from a text join in code?

It's the same operation, just visual. The page does what `text.replace(/\r?\n/g, ' ').trim()` would do in JavaScript. If you're scripting, do it in code; if you're cleaning a one-off paste, do it here.

Will it remove trailing whitespace and double spaces?

Yes if you toggle 'collapse multiple spaces' - useful when the original used multiple spaces for alignment. Trailing whitespace at the end of each line is removed before line concatenation.

Does it work for CJK text?

Yes. Newlines around Chinese/Japanese characters are removed without inserting Western spaces by default - East Asian punctuation conventions don't use spaces between characters. Toggle the 'preserve word spacing' option if your text mixes English and CJK.

Is my text uploaded?

No. Replacement runs in your browser. Pasted text is not transmitted.