Multiline anchors: lines ending in a semicolon
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. Match every line whose last character is a semicolon, from the first character of the line to that semicolon. The whole match is compared, and it must not include the line break.
What this exercise teaches
^.*;$ with the g and m flags matches whole lines that end in a semicolon. Without m, ^ and $ only see the start and end of the entire block, and without $ a semicolon in the middle of a line would be enough.
A hint if you get stuck
With the m flag, ^ and $ work on each line. A line with a semicolon only in the middle must not count, so keep the $.
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 exerciseMore exercises in Advanced
- Lookahead: amounts before USDFree
- Negative lookahead: not starting with unFree
- Lookbehind: amounts after $Free
- Negative lookbehind: positive numbers onlyFree
- Lazy vs greedy: the first quoted textFree
- Named groups: year, month, dayFree
- Password rules with lookaheadsFree
- Word boundaries: replace a whole wordFree
- Unicode letters with the u flagFree
- Multiline flag: TODO linesFree
- Backreference across lines: duplicate linesFree
- Multiline: trailing whitespace on every lineFree
- Named groups in a replacementFree
- Negative lookahead: numbers that are not percentagesFree