Whitespace Normalization Regex

Matches multiple consecutive whitespace characters for normalization.

パターン

/\s{2,}/g
→ ビジュアライザーで開く

テスト例

Hello World Foo Bar Baz

コード例

javascript

const normalized = str.replace(/\s{2,}/g, ' ').trim();

python

import re
normalized = re.sub(r'\s{2,}', ' ', text).strip()

go

import "regexp"
re := regexp.MustCompile(`\s{2,}`)
normalized := strings.TrimSpace(re.ReplaceAllString(text, " "))
whitespacecleanupstring