Earlier quoted context omitted.
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…
Regex character "$" doesn't mean "end-of-string"
351–360 of 382 posts
Re: Regex character "$" doesn't mean "end-of-string"
#352Earlier quoted context omitted.
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…
Perl spread regexes.
I took a look at Raku, which claims be a better Perl maybe, or closely related but more modern, it certainly looks nice. Although i am a big fan of typed languages, Raku piqued my interest.
Re: Regex character "$" doesn't mean "end-of-string"
#353Earlier quoted context omitted.
Python's behavior is not a hack, it is the common behavior. $ matches at the end of the string or before the last character if that is a newline, which is logically the same as the end of a single line. But as you said, you can have additional newlines inside of the string which is also the common behavior and not specific to python. Personally I think of this as you just assume that the string is a single line and m…
> Python's behavior [..] is the common behavior. The very post we're commenting on shows that that's not true: PHP, Python, Java and .NET (C#) share one behavior (accept "\n" as "$"), and ECMAScript (Javascript), Golang, and Rust share another behavior (do not accept "\n" as $). Let's not argue about which is “the most common”; all of these languages are sufficiently common to say that there is no single common behav…
Re: Regex character "$" doesn't mean "end-of-string"
#354Earlier quoted context omitted.
> 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"
#355In Lua it's only the start/end of the string > A pattern is a sequence of pattern items. A caret '^' at the beginning of a pattern anchors the match at the beginning of the subject string. A '$' at the end of a pattern anchors the match at the end of the subject string. At other positions, '^' and '$' have no special meaning and represent themselves. https://www.lua.org/manual/5.3/manual.html#6.4.1 Lua's pattern matc…
> In Lua it's only the start/end of the string There's an additional caveat: if you use the optional "init" parameter to specify an offset into the string to start matching, the ^ anchor will match at that offset , which may or may not be what you expect.
I find it hard to imagine any other expectation passing the rubber duck test.
"Oh, so you expected the match to always fail, no matter what the string was?"
Re: Regex character "$" doesn't mean "end-of-string"
#356Earlier quoted context omitted.
Perl spread regexes.
Super spreader event we've got ourselves into. I took a look at Raku, which claims be a better Perl maybe, or closely related but more modern, it certainly looks nice. Although i am a big fan of typed languages, Raku piqued my interest.
my Int $a = 42; # ok
my Int $a = "foo"; # Type check failed in assignment to $a; expected Int but got Str ("foo")
Re: Regex character "$" doesn't mean "end-of-string"
#357Earlier quoted context omitted.
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.
Re: Regex character "$" doesn't mean "end-of-string"
#358Earlier quoted context omitted.
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.
Android, Busybox and Muscl have entered the chat
Re: Regex character "$" doesn't mean "end-of-string"
#359Earlier quoted context omitted.
> In Lua it's only the start/end of the string There's an additional caveat: if you use the optional "init" parameter to specify an offset into the string to start matching, the ^ anchor will match at that offset , which may or may not be what you expect.
> which may or may not be what you expect I find it hard to imagine any other expectation passing the rubber duck test. "Oh, so you expected the match to always fail, no matter what the string was?"
Don't get me wrong, it's certainly far more useful as it is, I'm glad it works this way.
Re: Regex character "$" doesn't mean "end-of-string"
#360Earlier quoted context omitted.
Super spreader event we've got ourselves into. I took a look at Raku, which claims be a better Perl maybe, or closely related but more modern, it certainly looks nice. Although i am a big fan of typed languages, Raku piqued my interest.
In Raku, if you want to go typed, you can! It's called "gradually typed". my Int $a = 42; # ok my Int $a = "foo"; # Type check failed in assignment to $a; expected Int but got Str ("foo")