Regular Expressions For New Line

Category: Strings

A regular expression to match a new line (linebreaks).

Note that Linux uses \n for a new-line, Windows \r\n, and old Macs \r.

/[\r\n]+/

The regex above also matches multiple consecutive new lines. Use the following regex to fix that:

/(\r\n|\r|\n)/

See Also:

Rate This Regex
Sending
User Review
0 (0 votes)

Expression Flags

Flags Description
i Ignore case sensitive.
g Allows global search.
m Allows multiline search.