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
Search - "regular expression"
-
My own language, hence my own parser.
Reinvented the regular expression before realizing it already existed (Google didn't exist at the time).
I'm a living reference for regular expressions since then.7 -
When you have one problem and you decide to use regular expressions...
You need to know this: you have two problems now.3 -
Small Me(m): learning some basic code
Senior Dev(d): *walks by and sees my code*
m: hey got any advice on this?
d: learn to use regular expression. *walks away*
m: 30min later... *Mind blown*
And coffee of course ☕2 -
Me (as a Senior developer): How will you solve this problem using regular expression?
Junior developer: *Explains*
Me: Good
Junior developer: I truly feel like a programmer when I code regular expressions
Me: Now, we have two problems.26 -
New developers(5-6 years experience) these days are so pathetic. They dont have any sense of code review. All they want is to put their opinion out without giving any thought.
I had a PR for review today which contains mock specification to match a regular expression and return the corresponding response
The regular expression I put was
104000(02|06|20|48)
Now, this guy comes and puts a comment that we could "simplify" as 104000\d{2}
I replied, the ending digits are not contiguous. The specific pair of digits have to match for these mocks.
Then this guy replied, then we could simplify as 104(0{4}(2|6)l0{3}(20|48)).
I said, I cannot understand how that is simplification. Why do we need such a complex regex to match something very straight forward.
And the guy replied, we should be writing proper regexes, otherwise we could just specify everything explicitly.
I was like WTF man. You try deciphering this next week without taking at least a minute to know which values are matched.
Anyhow, another senior person approved my PR, and I merged it.12 -
I spent almost 10 hours coming up with this RegEx. Trial and erroring my way to hell. First I had get rid of the HTML tags (which was easy-ish) then I spent most of my time trying to figure out how to remove the god damn dash but keep hyphenated words ....... Then I found \B and look behinds...
I am making it a point to get good at this shit... Because right now I am petrified of it... Fuck you Regular expression you have taken away all my emotions...14 -
Playing around with Bard:
Me:Who called me from ...?
Bard: <blah blah blah> Would you like me to run a reverse phone lookup on that number for you?
Me: Yes
Bard: I'm just a language model, so I can't help you with that.
Me: Then why did you ask?
Bard: "I understand that you don't need me to run a reverse phone lookup, and that's perfectly fine. I just wanted to offer the service in case you were interested."
I tweaked the question and Bard responded with a Python script and a phone number regular expression.
Our jobs are safe for now.1 -
PHP arrays.
The built-in array is also an hashmap. Actually, it's always a hashmap, but you can append to it without specifying indexes and PHP will use consecutive integers. Its performance characteristics? Who knows. Oh, and only strings, ints and null are valid keys.
What's the iteration order for arrays if you use them as hashmaps (string keys)? Well, they have their internal order. So it's actually an ordered hashmap that's being called an array. And you can produce an array which has only integer keys starting with 0, but with non-sequential internal (iteration) order.
This array weirdness has some non-trivial implications. `json_encode` (serializes argument to JSON) assumes an array corresponds to a JSON array if its keys are consecutive integers in increasing order starting with 0, otherwise the array becomes a JSON object. `array_filter` (filters arrays/hashmaps using callback predicate) preserves keys, so it will punch holes in the int key sequence if non-last items are removed, thus turning arrays into hashmaps and changing your JSON structure if you forget to discard keys before serialization.
You may wonder how JSON deserialization works, then? There's a special class for deserialized JSON objects, `stdClass`. It's basically a hashmap too, but it's an object, not an array, and all functions that would normally accept arrays won't work with it. So basically its only use is JSON (de)serialization. You can even cast arrays to objects, producing `stdClass`.
Bonus PHP trivia:
Many functions return nonsensical values. `preg_match`, the regex matching function, returns 1 for success, 0 for no matches and false for malformed regular expression. PHP supports exceptions, so it could just throw one on errors. It would even make more sense to return true, false and null for these three cases. But no, 1, 0 and false. And actual matches are returned by output arg.
`array_walk_recursive`, a function supposed to recursively apply callback to each element of an array. That's what docs say. It actually applies it to leafs only. It will also silently accept object instead of array and "walk" it, but without recursing into deeper objects.
Runtime type enforcing is supported for function arguments and returned values. You can use scalar types, classes, array, null and a few special keywords. There's also a `mixed` keyword, which is used in docs and means "anything". It's syntactically valid, the parser will accept it, but it matches no values in runtime. Calling such function will always cause a runtime error.
Strings can be indexed with negative integers. Arrays can't.
ReflectionClass::newInstanceWithoutConstructor: "Creates a new class instance without invoking the constructor". This one needs no commentary.
`array_map` is pretty self-explanatory if you call it with a callback and an array. Or if you provide more arrays of equal length via varargs, callback will be called with more arguments, one from each array. Makes sense so far. Now, you can also call `array_map` with null instead of callback. In that case it treats provided arrays as rows of a matrix and returns that matrix, transposed.5 -
Guys. GUYS. There are so many freaking weird edge cases for regular expression evaluation. *head desk*8
-
it is just a wind mill near a well for non developers ..
but we know it a regular expression .. is not it ??😀3 -
This is the most wtf thing that happened me with Javascript, I had a regular expression and it caused bugs only with 4 digits long words, then I just noticed this:
/^.{3}$/.test(null) // false
/^.{4}$/.test(null) // true
What the fuck, I can't believe that who designed the .test method didn't think to avoid null coercion2 -
If you were to write a regular expression to match phone numbers in the format of either:
(123) 456-7890 or
123-456-7890
Would you prefer a regular expression that looked like:
A) /^(?:\(\d{3}\) |\d{3}-)\d{3}-\d{4}$/g
B) ^\(\d{3}\) \d{3}-\d{4}$|^\d{3}-\d{3}-\d{4}$/g
C) Other
D) I hate regex
Reasoning? Alternative? Discuss.
(I'm curious about preferences surrounding the readability of regular expressions)19 -
At work we have to split a potentially large ID into 2 10-digit long parts that will be passed to an outside system that will later return them with some more data to us.
A colleague had implemented it using regular expression, it passed code review, everything was ok, until he noticed a potential problem. For some cases, because the outside system stores them as int and therefore will remove any leading zeros, there will be no way to reconstruct the number.
So we brainstorm and I propose ether a modified regex, or to just use math like part1 = id % 10^10 and part2 = floor(id % 10^10) and then we can reconstruct it simply by: part2 * 10000000000 + part1
Colleague: - Well, the regex will be faster, there won't be any calculations
Me: - :| I disagree but ok..
We do some more brainstorming and testing and find a case where the proposed new regex fails as well
So I bring up my previous proposal, I explain what exactly it does.
Colleague: - I don't like the math, it has calculations, which won't be needed before we reach the 11th digit
Have I missed some major development in computer hardware? When did they become bad/slow at doing math? :|8 -
Restarting regular expression parser from scratch has been good. I am somehow both much farther to completion and farther away from completion than I was in the earlier implementation.
Further in the sense that this implementation is going to be way more flexible to changes in the language
Farther in that I haven’t even got all of the regex parts added to the first stage yet.
But I’m feeing good about it.
Even if I did refactor it so my constants are in all caps and now feel like my core is yelling at me.11 -
This regular expression documentation thing is coming along. Added capture groups and backreferences. Think I just need to tackle Unicode property escapes and control characters.
But now I feel like I should have implemented it differently. Like, maybe instead of “‘a’ followed by ‘b’ followed by ‘c’, I should have just done ‘abc’.
*sigh*1 -
Maybe not so wk65
but nobody posts a awesome regular expression?
come on, it says "exp."
someone gotta write one!
(not me, i suck with regex)1 -
TIL "Regular Expression DDOS" is a thing
I thought OS/server would be smart enough to cut short long running CPU intensive session-threads without affecting others, thats their job after all
I overestimate the OS-level I guess :v
https://security.snyk.io/vuln/... //ref15 -
I need to build a dynamic regular expression with matching 0 or more char, but \w doesn’t work.
new RegExp(‘^\/\w*#’ + route, ‘i’)
Any solution? 🥺14 -
While working on a problem my codding partner and I spent far too long trying to figure out why nothing was working with the deployment tool that we where given. The team that maintains the tool told us that all the scripts that we needed to write, to filter and add additional logic to the deployment process, was supposed to be in groovy,
after a couple of hours of having nothing but failed runs, we started poring through the tools official documentation just to find out that the feature we where using used JavaScript instead of groovy. 2 minuets latter everything worked.
The most puzzling thing with the problem is that the code was executing and just having issues with the regular expression that we used on line 20 or so -
My manager and coworkers kept calling me during vacation to add more triggers to fire some functionality. I had enough and made a regular expression matching, told them to learn regex and fuck off
-
My regex foo has gotten really weak. It took me unholy number of attempts to get ^\n{1,}$ right 😞.1
-
More like a confession.
Had a task that involved invalidating a string if it contained more than five digits (anywhere in the string.)
"No problem", I thought. That sounds like a simple regex!
^(\D*\d?\D*){5}$
Turns out catastrophic backtracking had other ideas, and I revert to my usual "atomic grouping fudge that will hopefully work without me really understanding what's going on" of:
^(?>\D*\d?\D*){5}$
...anyone else shamefully follow this mantra, or am I the only one that hasn't skilled up properly on regexes...7 -
So I have my little program which originally was written with intention to be useful for academics to deal with old fuck HPLC, but they got new one so I am not sure about it usefulness anymore. Basicly it reads HPLC report and take from it table and dilution number from name.
I spend like 2 hours trying to read all numbers from string which are between two given chars. Probably I could do it easier with regular expression or not being fucking moron or use sheet of paper to figure it out. Eventually I take traditional pen and paper and solve it in 10 minutes...
How to be unproductive 101 -
How To Validate Email Address In JavaScript?
I have been following this guide
But is there any other way i can validate email without using regular expression?20