Ranter
Join devRant
Do all the things like
++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatar
Sign Up
Pipeless API
From the creators of devRant, Pipeless lets you power real-time personalized recommendations and activity feeds using a simple API
Learn More
Comments
-
bad-frog5464ythis doesnt seem to be regex' fault.
correct me if im wrong, but i think the regex pattern per se is between / and /.
if anything i think its the "gi" flag in the end which does that weird behaviour. which would be implementation-specific (makes me think of sed regex)
i dont use regex very often, so please do correct me if im wrong -
bad-frog5464y@stop so its like in sed. ok, i get it this far.
but then what could possibly indicate that you are expecting alternating results? and even more importantly, what would be the use of having your results alternate?
people talk about c like its some arcane, ancient magic, but low level is actually a piece of cake compared to these high level languages' methods mumbo jumbo -
g is global.
First call of test.
First match.
Second call of test.
Second match or False if not found.
Third call of test.
Reset as previous match -> False, first match of test.
It's obvious....
And maybeeeeeee reading docs and utilizing variables would make this even more obvious. -
bad-frog5464y@IntrusionCM
tx for the enlightenment.
you might want to count the number of occurencies of a certain pattern and getting false tells you you arrived at the end of the string.
its obvious when you think of it that way.
had to think of it that way tho... -
@bad-frog :)
It's one of many reasons I hate JS so much.
The whole thing is a complete brain fucking shit.
It would be far more logical (and is implemented like this in many languages) if you either pass a reference in of a container datatype which gets filled with matches (e.g. PHP) or getting an object back which allows to access the matched groups (e.g Python).
But to allow a function call to behave like a generator while not being a "true" generator is fuckity.
Like a lot of APIs in JS. :)
My sassy ness was the result of having fun with this a long time ago. JS APIs are truly a marvelous cluster fuck.
I was pretty angry at that time and still am cause some dev thought it would be great to use this in a while loop fashion in a function. I'm still getting murderous intents remembering that. -
bad-frog5464y@IntrusionCM wow. they made javascript to look like c and be a full oop language, but they ended up with the worst of both worlds. and worse than that for this one: this method follows pure functionnal logic.
and now i have to learn this bullshit bc all our frontend belongs to java. *facepalm_9000 -
@bad-frog
I don't think this is functional at all.
A generator would e.g. stop yielding results after reaching end of iteration.
An iterator would throw an exception when trying to access an out of range element.
That's what makes me furious.
It could have done that.
But no. They start over, at the first element instead
Just think how funny e.g. for loops would be which automatically restart.
:@ -
bad-frog5464y@IntrusionCM lmao yeah, i see exactly what you mean.
i was thinking functionnal because how would you implement something like that in a functionnal style? : a while loop, calling a function returning a boolean, with a counter.
no structure needed whatsoever
exactly the same logic as the dev had behind this method. to be used in a while loop and a counter. (lol oop ur methods are woke functions)
what makes me wonder now, is how arrays work in java and what would be the behaviour of that method is if the string is changed between two calls... bc when i think about it, all this sounds inefficient as frig
Related Rants
I was genuinely baffled by this until I read up more on regex flags and realised that this is the intended behaviour😂
rant
regex