Regexdrill

Level 5: Advanced Exercise 69 of 70 Free

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 exercise

More exercises in Advanced