← Back to all regex patterns
Replace
Low backtracking risk
Regex to Collapse Blank Lines
Helpful when normalizing pasted docs, generated markdown, or support transcripts with too much vertical space.
Regex
/\n{3,}/gTry this pattern
Matches current input
line1
line2
1 match found in the current text.
Passing examples
- line1 line2
- a b
Failing examples
- line1 line2
- single line
Code examples
JavaScript
const regex = /\n{3,}/g;
regex.test(input);Python
import re
pattern = re.compile(r"\n{3,}")
bool(pattern.search(input))Go
re := regexp.MustCompile("\\n{3,}")
matched := re.MatchString(input)