Empty Lines Regex
Matches empty or whitespace-only lines for removal.
パターン
/^\s*$/gm
→ ビジュアライザーで開くテスト例
Line 1
Line 2
Line 3
Line 4
コード例
javascript
const cleaned = str.replace(/^\s*$/gm, '').replace(/\n+/g, '\n').trim();
python
import re cleaned = re.sub(r'^\s*$\n', '', text, flags=re.MULTILINE).strip()
go
import "regexp" re := regexp.MustCompile(`(?m)^\s*$\n`) cleaned := strings.TrimSpace(re.ReplaceAllString(text, ""))
whitespacecleanupmultiline