Why were ^ and $ chosen to indicate the beginning and end of a string in a regular expression?

Maybe there is some hidden and forgotten reason why these keys were chosen? In the same spirit as this link http://www.catonmat.net/blog/why-vim-uses-hjkl-as-arrow-keys/ explains the use of hjkl in vim and ~ in bash, maybe there is some something for ^ and $? In fact, the picture in this article on the terminal shown does not even have the ^ key.

I would really appreciate if anyone would say or show the keyboard layout used by Ken Thompson when he wrote the QED version that supports regex. (And if people stop trying to be funny in the comments).

edit:

Here are some answers. Even if they are just guesses, they can serve as great mnemonic material. Thanks! It’s just a pity you didn’t put it on hold so fast, maybe some people answered too slowly.

+5
source share
1 answer

Today, this question can hardly be answered, because regular expressions were introduced more than fifty years ago. I can share the versions that seem most reasonable to me.

The dollar sign symbolized the end of the line back in ed. The first practical implementation of RE was introduced specifically in ed and derivatives (e.g., QED). And the dollar sign has been reused. This meant either the end of the line or the last line, depending on the context. This is more or less clear, but the question of why the dollar sign was originally designated as the end of something else remains. It ('$') is represented by the “ASCII approximation” of the typographic sign “end of paragraph”.

As for “^” as the beginning of the line, it is probably the “ASCII approximation” of the Greek letter lambda, which meant an empty expression in early theoretical works: http://www.fing.edu.uy/inco/cursos/intropln/material/ p419-thompson.pdf

+1
source

Source: https://habr.com/ru/post/1236904/


All Articles