ANCHORS & BOUNDARIES
Start and end
`^` anchors a match to the start, `$` to the end.
Anchors match positions, not characters. ^ is the position before the first character, $ the position after the last. ^TODO matches TODO only when it starts the line; ;$ matches a semicolon only when it ends the line. ^$ matches an empty line - two positions, zero characters between them.
By default ^ and $ mean start and end of the WHOLE string. With the m (multiline) flag they match at every line break - that is what you want when scanning files. MDN: multiline.
PRACTICE - 3 DRILLS 0/3 DONE
Match TODO, but only when the line starts with it.
/ /
TODO: fix this
must match: "TODO"
// TODO later
must match nothing
TODO
must match: "TODO"
Match a semicolon, but only when it is the last character on the line.
/ /
let x = 1;
must match: ";"
a; b; c;
must match: ";"
no semicolon
must match nothing
Match import, but only when the line begins with it.
/ /
import fs from "fs"
must match: "import"
import later
must match nothing
reimport done
must match nothing
import
must match: "import"