Text Cleanup

Normalize Line Breaks

Ensure all newlines follow the same format (LF or CRLF).

Explanation

Windows (CRLF), Unix (LF), and old Mac (CR) use different characters for newlines. Mixing them causes issues in many tools.

Examples

Mixed Breaks
Output
Line 1\nLine 2\nLine 3

Code Examples

JavaScript
// Normalize to Unix (LF)
const normalized = input.replace(/\r\n|\r/g, '\n');

💡 Tips

  • Most modern systems prefer LF (\n)
  • Git can handle this conversion automatically if configured
  • Always normalize before running line-by-line regex

⚠️ Common Pitfalls

  • Some legacy Windows systems still strictly require CRLF