Regexdrill

Level 5: Advanced Exercise 67 of 70 Free

Multiline: trailing whitespace on every line

A regex exercise from Regexdrill. Solve it with a pattern box with live highlighting in your browser, checked against hidden test strings, and it is checked the moment you submit.

The task

Each test is a block of several lines. Remove the spaces and tabs at the end of every line. Blank lines must stay as blank lines, leading whitespace stays, and nothing else changes. Use the m flag.

What this exercise teaches

[ \t]+$ with the gm flags removes trailing spaces and tabs on every line. \s+$ would swallow line breaks too, joining a blank line to the line above it.

A hint if you get stuck

A class of space and tab, repeated, then $ with the m flag. \s also matches line breaks, which causes a problem here.

Try it now, free, no account needed

Every exercise on Regexdrill is free to try. Open it on the practice page, solve it, and get instant feedback with a hint. A free account adds the worked solution; Pro adds timed mode and the certificate.

Open this exercise

More exercises in Advanced