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:
- Regular Expression To Match Whitespace
- Regex To Match All Whitespace Except New Line
- Regex Match All Characters Except Space (Unless In Quotes)
- Regex To Match Any Word In A String Excluding Spaces
- Regex To Match Spaces And Empty Lines That Aren’t In Quotes
- Regex To Match Two Characters Surrounding A Single Space