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, " "))