Site icon javaniceday.com

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

The Jungle

The Jungle by Ian Capper is licensed under CC-BY-SA 2.0

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

Exit mobile version