How to remove more than two spaces and new lines with regex

How to remove more than two spaces and new lines with regex

To remove more than two spaces and new lines using regex, you can use the following pattern:

\s{2,}|[\r\n]+

This pattern matches any sequence of two or more whitespace characters (\s{2,}) or any sequence of one or more newline characters ([\r\n]+).

To remove these matches from your text using regex, you can use a regex function in your programming language of choice