Live data from Hacker News

Regex character "$" doesn't mean "end-of-string"

sethmlarson.dev

331–340 of 382 posts

Re: Regex character "$" doesn't mean "end-of-string"

#331

Earlier quoted context omitted.

It’s not that silly. You constantly get into escape conundrums because you need to use a metacharacter which is also a metacharacter three levels deep in some embedding. (But that might not solve that problem? Maybe the problem is mostly about using same-character delimiters for strings.) And I guess that’s why Perl is so flexible with regards to delimiters and such.

Yes, languages really need some sort of "raw string" feature like Python (or make regex literals their own syntax like Perl does). That's the solution here, not using weird characters...

Fine enough. But I wonder why strings have to use the same delimiter. Imagine if you had a list delimiter `|` and the answer to nested lists was “ohh, use raw list syntax, just make `###||` when you are three levels deep or something”.

Re: Regex character "$" doesn't mean "end-of-string"

#332

Earlier quoted context omitted.

Regexes are one case where I think it's already extremely unbalanced wrt being easy to write but hard to read. Using stuff like special Unicode chars for this would make them harder to write but easier to read, which sounds like a fair deal to me. In general, I'd say that regexes should take time and effort to write, just because it's oh-so-easy to write something that kinda sorta works but has massive footguns. I wo…

Regexes originate from Perl, or they were popularized by Perl if i got this right. In Perl readable code is not ranked as one of it's top 100 priorities. Regexes could originate from J and situation could be even worse though!

Regex's predate perl quite substantially. Think grep and friends if nothing else.

Certainly making the perlre library available separate to perl encouraged its widespread use, and lots of others copied or were inspired by it.

"Popularized" doesn't seem like quite the right word though, I don't disagree with the point, but if I shout "Hey everyone let's write regex's" at the office people throw stationary at me, which is not true of other popular things!

Re: Regex character "$" doesn't mean "end-of-string"

#333
post #162

Earlier quoted context omitted.

...and if you can understand them then you clearly understand regex enough not to need ChatGPT to write them

I understand assembly too.

The only time you'd want to write assembly in production code would be if you need to hand roll some optimisation. So I don't really understand your point here,

Re: Regex character "$" doesn't mean "end-of-string"

#334
post #138

Earlier quoted context omitted.

Yeah, omitting what is arguably the language most associated with regexes seems a bit of an oversight. I guess it shows how far off the radar Perl currently is.

> I guess it shows how far off the radar Perl currently is. This is a serious misconception. Perl is far, far from dead. The constant activity of the gargantuan CPAN library more than demonstrates very much the opposite. I would say Perl and its community has done quite well considering it hasn't had the same mountain of corporate funds thrust into it like more highlighted have. Mainstream ain't everything.

I don't think "off the radar" means dead, but that people aren't generally aware of what's going on with it. I think this is actually pretty consistent with what you're saying; stuff is going on with it, but it's not on people's radar, so they don't realize it.

Re: Regex character "$" doesn't mean "end-of-string"

#336
post #58

Earlier quoted context omitted.

"I will hire you anyway, but I will pay you less" Regex, useful in any job...

regex is useful but chatgpt is amazing at it, so why spend a minute keeping such useless knowledge in mind. if you know where to find something no point in knowing it.

Sure, why bother understanding anything if ChatGPT can just produce the answers for you ;). You don't have to understand the answers even. Actually you don't need to understand the question also. Just forward the question from your manager to ChatGPT and forward the answer back to your manager ;). Why make life difficult for yourself?

Re: Regex character "$" doesn't mean "end-of-string"

#337

Earlier quoted context omitted.

re.match('^bob$', 'bob') → yes re.match('^bob$', 'bobs') → no Most people would expect 'bob\n' not to match, because I used '$' and it has an extra character at the end, just like 'bobs'. In Python it does match because '\n' is a special case.

... for some arbitrary definition of "most people".

That’s true, probably fewer than ten million people in the world would have an opinion one way or the other. :)

Re: Regex character "$" doesn't mean "end-of-string"

#338
post #8

Regexp was one of the first things I truly internalized years ago when I was discovering Perl (which still lives in a cozy place in my heart due to a lovely “Camel” book). Today most important bit of information is knowledge that implementations differ and I made a habit of pulling reference sheet for a thing I work with. E.g. Emacs Regexp annoyingly doesn’t have word in form of “\w” but uses “\s_-“ (or something no…

How did you internalize it? Perl looks like cat keyboarding.

Perl has few “sigils” which are basically types: $scalar, @array and %hash. And few syntactically equivalent operators. Also a set of global variables with character shorthands like `$.`. Apart from that it’s a regular language.

Re: Regex character "$" doesn't mean "end-of-string"

#339
post #51

Earlier quoted context omitted.

No gnu tool can balance brackets, afaics. So you can't do everything in sed. And sed is, by design, useless for matching text that spans lines, so good luck picking out paragraphs with it.

I am pretty sure even pure Awk can do it; or am I mistaken? I thought there was an even more sophisticated example in the Awk book. Edit: oh, you mean via regex engines available in GNU tools; I am dumb. Hmm... is there no GNU extension with PCRE?

Nope. Gnu regex tools also do not support lookahead or alternation. Lookahead is really useful.

It's a problem for Linux that it can't move on. The cold dead hand of gnu is firmly around the community's neck.

Re: Regex character "$" doesn't mean "end-of-string"

#340

Earlier quoted context omitted.

The whole \r is archaic. It doesn't even behave properly in most cases. Just use \n everywhere and bite the lemon for a short while to fix your problems. And if you believe \r\n is the way to go, please make sure \n\r also works as they should have the same results. (or \r\n\r\r\r\r for that matter)

Why did they even decide to use two characters for the end of line? Seems bizarre. I could have imagined that `\r` and `\n` was a tossup. But why both?

Carriage Return (\r) - move to start of line

Line Feed (\n) - move down 1 line

Essentially, when you're sending commands to teletypes, that's how you'd have to do it.

Post reply on HN