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?

laurent
  • 88,262
  • 77
  • 290
  • 428
  • 3
    Personally, I reckon [they] just chose two characters that hadn't been assigned yet. – Bojangles Sep 03 '12 at 14:28
  • 1
    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. – Shiplu Mokaddim Sep 03 '12 at 14:35
  • 3
    $ represents the newline character(s) in asm language, I think this is related – Eregrith Sep 03 '12 at 14:35

5 Answers5

7

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

Blue Magister
  • 13,044
  • 5
  • 38
  • 56
1

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

Daniel Hilgarth
  • 171,043
  • 40
  • 335
  • 443
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 :-)

user711413
  • 761
  • 5
  • 12
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.

Clement J.
  • 3,012
  • 26
  • 29
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.

weston
  • 54,145
  • 21
  • 145
  • 203