Why is the start of a line "^" and the end of line "$"?
Asked Answered
D

5

7

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?

Demoss answered 3/9, 2012 at 14:24 Comment(3)
Personally, I reckon [they] just chose two characters that hadn't been assigned yet.Vanbuskirk
Dont know about the reason. But they never confuses me. My thinking is different. Every time I see ^, $ I interpret it as start and end. E.G. See the $ of the document. If you ever use vi you'll notice 0, $ means start and end.Nitrification
$ represents the newline character(s) in asm language, I think this is relatedFuge
C
7

One mnemonic: In an auction, bidders start by raising ^ their paddles. The price $ is established at the end.

Carrillo answered 3/9, 2012 at 14:34 Comment(0)
F
1

I memorize ^ as: It points to where it came from, i.e. the previous line, so it should stand at the beginning.

Fought answered 3/9, 2012 at 14:26 Comment(0)
M
1

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 :-)

Microprint answered 3/9, 2012 at 20:50 Comment(0)
P
0

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.

Pelagi answered 3/9, 2012 at 14:28 Comment(5)
And it would be backwards because?Ludovick
Seems you need to remember the word backword with this rule too.Nitrification
@lc.: What is your comment supposed to ask? It is not backwards.Fought
@DanielHilgarth The fact that $ (4) comes before ^ (6), at least on a US layout.Ludovick
@Ludovick ah, ok. On my german layout ^ is to the left of 1 and $ is on 4 :-)Fought
C
0

\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.

Capable answered 3/9, 2012 at 14:38 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.