Skip to main content
Regexflux

Multiple Whitespace

beginner

Matches sequences of 2+ whitespace characters for collapsing.

whitespacenormalizecleanupformatting

Pattern

/\s{2,}/g

Try It

0 of 6 strings matched

Explanation

Matches two or more consecutive whitespace characters. Replace with a single space to normalize whitespace in text.

Test Strings

Matching

  • too many spaces
  • tab here
  • mixed spaces

Non-matching

  • single space
  • no-spaces
  • a b c

Language Compatibility

LanguageSupport
JSFull support
PYTHONFull support
JAVAFull support
PHPFull support
GOFull support

Code Snippets

const regex = /\s{2,}/g;
const text = "your text here";
const matches = text.match(regex);
console.log(matches);

Related Patterns