Skip to main content
AI Assist is now on Stack Overflow. Start a chat to get instant answers from across the network. Sign up to save and share your chats.
Active reading.
Source Link
Peter Mortensen
  • 31.4k
  • 22
  • 110
  • 134

Try thisthe following code,. It works on all platforms:.

var break_for_winDOS = 'test\r\nwith\r\nline\r\nbreaks'; var break_for_linux = 'test\nwith\nline\nbreaks'; var break_for_older_mac = 'test\rwith\rline\rbreaks'; break_for_winDOS.replace(/(\r?\n|\r)/gm, ' '); //output 'test with line breaks' break_for_linux.replace(/(\r?\n|\r)/gm, ' '); //output 'test with line breaks' break_for_older_mac.replace(/(\r?\n|\r)/gm, ' '); //output Output 'test with line breaks' 

Try this code, works on all platforms:

var break_for_winDOS = 'test\r\nwith\r\nline\r\nbreaks'; var break_for_linux = 'test\nwith\nline\nbreaks'; var break_for_older_mac = 'test\rwith\rline\rbreaks'; break_for_winDOS.replace(/(\r?\n|\r)/gm, ' '); //output 'test with line breaks' break_for_linux.replace(/(\r?\n|\r)/gm, ' '); //output 'test with line breaks' break_for_older_mac.replace(/(\r?\n|\r)/gm, ' '); //output 'test with line breaks' 

Try the following code. It works on all platforms.

var break_for_winDOS = 'test\r\nwith\r\nline\r\nbreaks'; var break_for_linux = 'test\nwith\nline\nbreaks'; var break_for_older_mac = 'test\rwith\rline\rbreaks'; break_for_winDOS.replace(/(\r?\n|\r)/gm, ' '); //output 'test with line breaks' break_for_linux.replace(/(\r?\n|\r)/gm, ' '); //output 'test with line breaks' break_for_older_mac.replace(/(\r?\n|\r)/gm, ' '); // Output 'test with line breaks' 
Source Link

Try this code, works on all platforms:

var break_for_winDOS = 'test\r\nwith\r\nline\r\nbreaks'; var break_for_linux = 'test\nwith\nline\nbreaks'; var break_for_older_mac = 'test\rwith\rline\rbreaks'; break_for_winDOS.replace(/(\r?\n|\r)/gm, ' '); //output 'test with line breaks' break_for_linux.replace(/(\r?\n|\r)/gm, ' '); //output 'test with line breaks' break_for_older_mac.replace(/(\r?\n|\r)/gm, ' '); //output 'test with line breaks'