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

The Jungle
Reading Time: < 1 minutes

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


About the author

Andrés Canavesi
Andrés Canavesi

Software Engineer with 15+ experience in software development, specialized in Salesforce, Java and Node.js.


Related posts


Leave a Reply

%d bloggers like this: