<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Sam Grg</title>
    <description>The latest articles on DEV Community by Sam Grg (@sam_grg_8d2507373f8d96b88).</description>
    <link>https://dev.to/sam_grg_8d2507373f8d96b88</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4240544%2F6724a003-434d-46ab-8cc4-37b22d86dd2f.png</url>
      <title>DEV Community: Sam Grg</title>
      <link>https://dev.to/sam_grg_8d2507373f8d96b88</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sam_grg_8d2507373f8d96b88"/>
    <language>en</language>
    <item>
      <title>How to Remove Line Breaks and Markdown When Copying from ChatGPT (and PDFs)</title>
      <dc:creator>Sam Grg</dc:creator>
      <pubDate>Thu, 12 Nov 2026 08:16:55 +0000</pubDate>
      <link>https://dev.to/sam_grg_8d2507373f8d96b88/how-to-remove-line-breaks-and-markdown-when-copying-from-chatgpt-and-pdfs-22kj</link>
      <guid>https://dev.to/sam_grg_8d2507373f8d96b88/how-to-remove-line-breaks-and-markdown-when-copying-from-chatgpt-and-pdfs-22kj</guid>
      <description>&lt;p&gt;If you regularly copy text from &lt;strong&gt;ChatGPT&lt;/strong&gt;, &lt;strong&gt;PDFs&lt;/strong&gt;, or &lt;strong&gt;web pages&lt;/strong&gt; into Google Docs, Microsoft Word, Notion, or emails, you have probably run into the same frustrating problem: broken paragraphs, random hard line breaks, and leftover Markdown (&lt;code&gt;**bold**&lt;/code&gt;, &lt;code&gt;###&lt;/code&gt; headings, backticks).&lt;/p&gt;

&lt;p&gt;Here is why it happens and the fastest ways to fix it — whether you prefer keyboard shortcuts, JavaScript regex, or a 1-click browser tool.&lt;/p&gt;




&lt;h3&gt;
  
  
  Why Copy-Pasted Text Breaks
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;PDFs&lt;/strong&gt; store a hard line break at the end of every printed line rather than every sentence. Copying a paragraph brings every visual line break along.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;ChatGPT &amp;amp; AI tools&lt;/strong&gt; output raw Markdown with double/triple newlines, &lt;code&gt;**&lt;/code&gt; bold markers, and &lt;code&gt;###&lt;/code&gt; headings. Pasting into Word or Docs often leaves raw symbols or extra gaps behind.&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  Method 1: Quick Regex in JavaScript
&lt;/h3&gt;

&lt;p&gt;If you are building a web app or cleaning text in the browser console, you can normalize line breaks and collapse extra whitespace in two lines of JavaScript:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;cleanText&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;rawText&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;\&lt;span class="n"&gt;r&lt;/span&gt;\&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;\&lt;span class="n"&gt;r&lt;/span&gt;&lt;span class="o"&gt;|&lt;/span&gt;\&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="o"&gt;+/&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;' '&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;\&lt;span class="n"&gt;s&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;' '&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you want to preserve paragraph breaks while collapsing triple newlines:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="n"&gt;cleanParagraphs&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;rawText&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;\&lt;span class="n"&gt;r&lt;/span&gt;\&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'\n'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;replace&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;\&lt;span class="n"&gt;n&lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="mi"&gt;3&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="o"&gt;/&lt;/span&gt;&lt;span class="n"&gt;g&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="s1"&gt;'\n\n'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
  &lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;trim&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h3&gt;
  
  
  Method 2: Built-In App Shortcuts
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Microsoft Word:&lt;/strong&gt; Press &lt;code&gt;Ctrl + H&lt;/code&gt;, search for &lt;code&gt;^p&lt;/code&gt; (paragraph break) or &lt;code&gt;^l&lt;/code&gt; (manual line break), and replace with a single space.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Google Docs:&lt;/strong&gt; Press &lt;code&gt;Ctrl + H&lt;/code&gt;, check &lt;strong&gt;Use regular expressions&lt;/strong&gt;, search for &lt;code&gt;\n&lt;/code&gt;, and replace with a space.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Excel:&lt;/strong&gt; Use &lt;code&gt;=CLEAN(SUBSTITUTE(A1, CHAR(10), " "))&lt;/code&gt; to strip newline characters inside cells.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Method 3: 1-Click Free Online Cleaners (No Sign-Up)
&lt;/h3&gt;

&lt;p&gt;If you don't want to run regex or Find &amp;amp; Replace every time, I built a fast, 100% client-side set of text utilities that run locally in your browser (nothing is uploaded or stored):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://linebreakremover.com/" rel="noopener noreferrer"&gt;Line Break Remover&lt;/a&gt;&lt;/strong&gt; — Paste text from PDFs, emails, or docs and replace line breaks with spaces, commas, or custom delimiters in one click.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;&lt;a href="https://linebreakremover.com/tools/chatgpt-text-formatter.html" rel="noopener noreferrer"&gt;ChatGPT Text Formatter&lt;/a&gt;&lt;/strong&gt; — Strips extra line breaks, removes Markdown (&lt;code&gt;**&lt;/code&gt;, &lt;code&gt;*&lt;/code&gt;, &lt;code&gt;###&lt;/code&gt;, &lt;code&gt;`&lt;/code&gt;), and cleans bullet prefixes before pasting into Word, Docs, or email.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Hope this saves you a few minutes of manual cleanup! Let me know what other text-cleaning edge cases trip you up.&lt;/p&gt;

</description>
      <category>productivity</category>
    </item>
  </channel>
</rss>
