Newline Counter

Counts the number of line breaks in text (recognizing \r\n, \r, and \n), which is one less than the total line count for text without a trailing newline. A free online tool from Staaarter, right in your browser.

Runs locallyUpdated 2026-07-22

Overview

Introduction

Sometimes you specifically need the number of line breaks, not the total line count, when checking a file format's expectations or debugging line-ending issues.

It runs entirely client-side, so nothing you paste is ever uploaded to a server.

What Is Newline Counter?

A counter that reports how many line break sequences (\r\n, \r, or \n) appear in the text.

It runs entirely client-side as part of this site's String Tools collection, so nothing you paste is ever uploaded to a server.

How Newline Counter Works

A regex matching any of the three line-ending styles is used with match() to count occurrences.

The transformation happens synchronously in JavaScript the moment you type, with no network round trip involved.

When To Use Newline Counter

Use it when verifying a file's exact newline count, or debugging inconsistent line endings in a document.

It's a fast way to get the answer without opening a code editor, a REPL, or writing a one-off script just to check.

Often used alongside String Length Counter and Empty Line Remover.

Features

Advantages

  • Correctly counts \r\n as one newline, not two.

Limitations

  • Doesn't distinguish which line-ending style was used, only the total count.

Examples

Counting newlines in a short list

Input

line one
line two
line three

Output

2

Three lines are separated by two newline characters.

Best Practices & Notes

Best Practices

  • Use Find the Length of a String if you want total line count instead of just the break count.

Developer Notes

The regex `/\r\n|\r|\n/g` matches \r\n as a single unit before falling back to lone \r or \n, so Windows-style line endings aren't double-counted.

Newline Counter Use Cases

  • Verifying a file's exact newline count
  • Debugging inconsistent or mixed line endings
  • Checking a document against a line-break-based limit

Common Mistakes

  • Confusing newline count with total line count; they differ by one for text without a trailing newline.

Tips

  • Pair with Find the Length of a String for a complete picture of a document's line structure.

References

Frequently Asked Questions