Why is the start of a line “^” and the end of line “$”?
-
30-06-2021 - |
Question
I never remember whether ^
matches the beginning of the line and $
matches the end of it or the other way around. A good mnemonic would be that the $
sign is always before the price, therefore it matches the beginning of a line - unfortunately it's the other way around.
So is there any reason why these two characters were chosen for the beginning and end of line?
Solution
One mnemonic: In an auction, bidders start by raising ^
their paddles. The price $
is established at the end.
OTHER TIPS
I memorize ^
as: It points to where it came from, i.e. the previous line, so it should stand at the beginning.
The $ used to mean the end of the line in very early editors, like ed. The ^ was probably chosen because it was about the last unused character on keyboards at the time :-)
This is probably due to the relative positions of these two characters on a QWERTY keyboard: '^' in first position (start of line) and '$' after (end of line).
EDIT: My bad, this is only valid on a french keyboard (AZERTY). It provides a mnemonic for AZERTY user but not an explanation.
\A
and \Z
do roughly the same, except they are subtly different to ^
/$
with respect to new line characters.
So if you remember that and also remember that ^
looks most similar to A
and $
is most simliar to Z
that might be enough of a mnemonic.