Text Processingflags: gm
Trailing Whitespace (Per Line)
Match trailing spaces and tabs at the end of each line — the regex linters use to flag dirty whitespace.
Try it in RegexPro →Available in
Pattern
regexengine-agnostic
[ \t]+$ (flags: gm)Raw source: [ \t]+$
How it works
[ \t]+ matches one or more space or tab characters. $ with the m (multiline) flag anchors to the end of EACH line, not the whole string. The g flag iterates so a multi-line string surfaces every offending line. Pair with `replace(re, '')` to strip.
Examples
Input
good line\nbad line \nfineMatches
Input
tab here\tand more\t\tMatches
\t\t
Input
no trailing spaceNo match
—Common use cases
- •Linter / formatter rules (eslint, prettier, gofmt)
- •Pre-commit hooks for cleanup
- •Markdown source hygiene
- •Git diff noise reduction
Related patterns
Whitespace Trim (Leading & Trailing)
Text ProcessingMatch leading and/or trailing whitespace on a string — the regex equivalent of .trim().
Whitespace-Only Line
Text ProcessingMatches lines containing only whitespace (or empty lines).
Single-Line Comment (// or #)
Text ProcessingMatch single-line comments using either the `//` (C-family) or `#` (shell, Python, Ruby, YAML) marker.
Emoji (Unicode)
Text ProcessingMatch emoji characters across the main Unicode emoji ranges — requires the Unicode flag in JavaScript.