Live data from Hacker News

Why do regexes use `$` and `^` as line anchors? (2024)

buttondown.com

41–48 of 48 posts

Re: Why do regexes use `$` and `^` as line anchors? (2024)

#41
post #15

IIRC, the original ASCII standard had ↑ and ← but later changed them to ^ and _, respectively.

ASCII 1963 was the first version of the standard and it had ← https://dl.acm.org/doi/10.1145/366707.367524

The 1965 draft had _ instead https://dl.acm.org/doi/10.1145/363831.363839

The first standard edition with _ was 1968 https://www.rfc-editor.org/info/rfc20

The 1977 version is also available https://nvlpubs.nist.gov/nistpubs/Legacy/FIPS/fipspub1-2-197...

Xerox PARC used ASCII 1963 (for reasons I have yet to unearth) so its programming languages Mesa and SmallTalk used ← for assignment and camelCase to separate words in identifiers. This stylistic quirk was carried over to later object-oriented programming languages.

Re: Why do regexes use `$` and `^` as line anchors? (2024)

#43
post #40
post #38

Earlier quoted context omitted.

It's a peso sign. The English word for the Spanish "peso" at the time was "dollar", and the US dollar was initially defined to be equal to the Spanish "dollar". The US dollar, which was a coin, had the same value as the Spanish peso because it consisted of the same weight (in Spanish, "peso") of silver. So the US used the peso sign for its dollars. Unicode calls it a "dollar sign" because that's what ASCII calls it,…

> > also known as ... "piece of eight" I wonder if it is a coincidence that "peso" sounds pretty similar to "piece of"

From the rae, https://dle.rae.es/peso:

(From) latin, pensum.

Piece, from https://www.etymonline.com/word/piece#etymonline_v_14956

c. 1200, pece, "fixed amount, measure, portion;" c. 1300, "fragment of an object, bit of a whole, slice of meat; separate fragment, section, or part," from Old French piece "piece, bit portion; item; coin" (12c.), from Vulgar Latin pettia, probably from Gaulish pettsi (compare Welsh peth "thing," Breton pez "piece, a little"), perhaps from an Old Celtic base kwezd-i-, from PIE root kwezd- "a part, piece" (source also of Russian chast' "part").

So yes, it looks like coincidence.

(Peso is a word in Spanish and up until modern times, there's very little transfer from English to Spanish)

Re: Why do regexes use `$` and `^` as line anchors? (2024)

#44
post #40

Earlier quoted context omitted.

> > also known as ... "piece of eight" I wonder if it is a coincidence that "peso" sounds pretty similar to "piece of"

From the rae, https://dle.rae.es/peso : (From) latin, pensum. Piece, from https://www.etymonline.com/word/piece#etymonline_v_14956 c. 1200, pece, "fixed amount, measure, portion;" c. 1300, "fragment of an object, bit of a whole, slice of meat; separate fragment, section, or part," from Old French piece "piece, bit portion; item; coin" (12c.), from Vulgar Latin pettia, probably from Gaulish pettsi (compare Welsh peth…

It does make me wonder, what's the oldest word in Spanish that's taken from English?

Off the top of my head, whiskey is the oldest, but I'm sure there's probably something much older

Re: Why do regexes use `$` and `^` as line anchors? (2024)

#45

I remember when learning regexes, struggling to remember which of ^ and $ were the beginning or end of the line. I know that my (and many other) shells used $ as the prompt symbol - i.e. at the beginning of what I was to type in the terminal. It being at the beginning of that line made it easy for me to remember that it also marks the beginning of regexes. Of course I was 100% incorrect as $ is in fact the end-of-lin…

Idk why anyone would ever "learn regex's" without the use of a look up table. It's not like timestables where having it memorized will really accelerate other aspects of life. Knowing what ^ does by memory will almost never benefit you.

Depends if you decide to use vim as an editor. By now it's second nature (even though I'm nowhere near a vim master and struggle) this is one thing I use often.

Re: Why do regexes use `$` and `^` as line anchors? (2024)

#46
post #40
post #38

Earlier quoted context omitted.

It's a peso sign. The English word for the Spanish "peso" at the time was "dollar", and the US dollar was initially defined to be equal to the Spanish "dollar". The US dollar, which was a coin, had the same value as the Spanish peso because it consisted of the same weight (in Spanish, "peso") of silver. So the US used the peso sign for its dollars. Unicode calls it a "dollar sign" because that's what ASCII calls it,…

> > also known as ... "piece of eight" I wonder if it is a coincidence that "peso" sounds pretty similar to "piece of"

The phonetics would have been even more similar at the time, but I suspect it's a coincidence. The words stem from different origins†, the sense development of "piece" is straightforward (a coin was a chunk of precious metal cut off the end of an ingot, thus being a piece of that ingot, and struck), and the chronology is probably wrong for a phonetic influence. https://www.etymonline.com/word/piece says "piece" for a coin is "c. 1400", which would be about 200 years older than the earliest attested occurrence of "piece of eight" and 100 years older than the peso itself, which was introduced in 01497.

However, the earliest attestation given in https://archive.org/details/oed07arch/page/836/mode/1up?view... is from 01575, in Scots: "To be payit all in half mark pecis," and the first attestation of "piece of eight" is from 01610: "Round trunkes, Furnish'd with pistolets, and pieces of eight." Maybe Etymonline knows of a much earlier attestation? Because if "piece" in the sense of "coin" really didn't come into use until the late 16th century, a phonetic influence would be much more plausible.

______

† "Peso", like "poise", is from Latin "pensum", "weight", which may be from "pensare", the frequentative of "pendere", "to hang, to weigh", while "piece" comes from Latin "petia" or "pecia", "fragment". In Spanish today "peso" is still the normal word for "weight" (and "pesar" is the normal verb for "weigh") and "pieza" is still a fairly common word for "fragment".

Re: Why do regexes use `$` and `^` as line anchors? (2024)

#47

Earlier quoted context omitted.

From the rae, https://dle.rae.es/peso : (From) latin, pensum. Piece, from https://www.etymonline.com/word/piece#etymonline_v_14956 c. 1200, pece, "fixed amount, measure, portion;" c. 1300, "fragment of an object, bit of a whole, slice of meat; separate fragment, section, or part," from Old French piece "piece, bit portion; item; coin" (12c.), from Vulgar Latin pettia, probably from Gaulish pettsi (compare Welsh peth…

It does make me wonder, what's the oldest word in Spanish that's taken from English? Off the top of my head, whiskey is the oldest, but I'm sure there's probably something much older

Part of the reason for this is that English didn't even exist until fairly recently (though still before modern times). But there were various Germanic languages, some of which English evolved from. There are a fair number of Spanish words of Germanic origin, some fairly old, perhaps dating from the Visigothic kingdoms in Iberia: guerra, guante, rico, orgullo, arpa, blanco, banco, frasco, yelmo, flecha, emboscar, jardín, flotar, bisonte, etc.

More specifically with respect to English, though, https://en.wikipedia.org/wiki/List_of_Spanish_words_of_Germa... says that bote comes from Old English "bāt" via Middle English "boot" and then Old French "bot". The other words in that category include arlequín, este, norte, oeste, and sur/sud-. But when did those words make the jump into Spanish? Some, like arlequín, were fairly recent!

"Old French" was supposedly spoken up to the mid-14th century, so words that came into Spanish directly from Old French probably came in before 01375 CE. But there's always the possibility that the word lingered for a century or three in some intermediate dialect like Occitan or Catalan before making it into Spanish. Unfortunately I don't know of any resource in Spanish comparable to the OED or Etymonline to find old Spanish attestations.

Post reply on HN