Skip to content

Instantly share code, notes, and snippets.

@acemir
Created June 29, 2018 16:05
Show Gist options
  • Save acemir/204612360042109a33e1d372761ad877 to your computer and use it in GitHub Desktop.
Save acemir/204612360042109a33e1d372761ad877 to your computer and use it in GitHub Desktop.
Match literal \r\n and trasform to <p></p>
// Match literal \r and literal \n
'<p>' + (str || '').split(/(?:\\[rn])+/g).join('</p><p>') + '</p>';
// Match all carriage returns \r, newlines \n and also literal \r and literal \n
'<p>' + (str || '').split(/(?:\\[rn]|[\r\n]+)+/g).join('</p><p>') + '</p>';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment