Live data from Hacker News

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

buttondown.email

11–19 of 19 posts

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

#11

[flagged]

I clicked this link because the question is interesting. Yes the answer won't change my life, or even make me more money, but it got me curious. That's why I don't think your response is helpful or insightful.

[flagged]

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

#13

They're because that's what Bill Joy used in vi back in 1979 to move to the beginning and end of a line. It made sense to use them for regex too.

Per the article, these anchors appear in Ken Thompson's port of the QED text editor, which dates back to 1970.

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

#14

Not sure about $ sign, but ^ probably comes from ADM-3A: https://en.wikipedia.org/wiki/ADM-3A#Legacy And here is a photo of its keyboard: https://twitter.com/toresbe/status/1756800589340549609/photo...

Per the article, these anchors appear in Ken Thompson's port of the QED text editor which dates back to 1970, years before even the ADM-1 terminal.

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

#16
> So there you have it, an explanation for the regex anchors that kinda makes sense.

That’s not an explanation, it’s speculation. The whole article was guess work and you picked something that sounded plausible. Ken Thompson is alive, why not ask and confirm? Then you could say you have an explanation.

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

#17
post #16

> So there you have it, an explanation for the regex anchors that kinda makes sense. That’s not an explanation, it’s speculation . The whole article was guess work and you picked something that sounded plausible. Ken Thompson is alive, why not ask and confirm? Then you could say you have an explanation.

Explanations and speculation: are they mutually exclusive? I'd say an answer from Ken Thompson would be a definitive explanation that might disprove the author's explanation, but that doesn't mean it's not an explanation.

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

#18
post #16

> So there you have it, an explanation for the regex anchors that kinda makes sense. That’s not an explanation, it’s speculation . The whole article was guess work and you picked something that sounded plausible. Ken Thompson is alive, why not ask and confirm? Then you could say you have an explanation.

Explanations and speculation: are they mutually exclusive? I'd say an answer from Ken Thompson would be a definitive explanation that might disprove the author's explanation, but that doesn't mean it's not an explanation.

[deleted]

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

#19
post #16

> So there you have it, an explanation for the regex anchors that kinda makes sense. That’s not an explanation, it’s speculation . The whole article was guess work and you picked something that sounded plausible. Ken Thompson is alive, why not ask and confirm? Then you could say you have an explanation.

Explanations and speculation: are they mutually exclusive? I'd say an answer from Ken Thompson would be a definitive explanation that might disprove the author's explanation, but that doesn't mean it's not an explanation.

> Explanations and speculation: are they mutually exclusive?

Yes. You only need to speculate when you don’t have a firm explanation.

> disprove the author's explanation

Speculation is “the forming of a theory or conjecture without firm evidence”, which is what the author is doing. They’re not explaining, they’re guessing at a reason.

Post reply on HN