|
I was chasing a "bug" all day. I finally solved it by realizing it wasn't a bug.
The "bug" was this - I was inputting a regular expression, and minimizing it, getting a new, simplified regular expression. Here's the original expressions
(foo|ba[rz])+[A-Z_a-z][A-Z_a-z0-9]*
Here was the expression I was getting out:
(ba[rz][A-Z_a-z]|foo[A-Z_a-z])[0-9A-Z_a-z]*
Notice there's no initial loop like in the original expression - just the loop at the end.
I thought it was wrong. It's not. While it could further be simplified into this:
(ba[rz]|foo)[A-Z_a-z][0-9A-Z_a-z]*
it wasn't actually wrong, which was what I thought the problem was.
Of course that's an equiv regex because foo, bar, and baz would all be matched with [A-Z_a-z][0-9A-Z_a-z]* !
*headdesk*
Real programmers use butterflies
|
|
|
|
|
After all these years, RegEx is still Voodoo to me and I don't really grok it. I usually copy regex scripts from the internet and tweak them a little, if needed.
Glad you figured it out.
|
|
|
|
|
It's a very simple functional language. I think the trouble people have with it is the operators are very short.
There's only a few core ones though. The rest is just syntactic sugar/shortcuts for them.
() * and |
that's all you need technically, although expressions would get pretty long.
Real programmers use butterflies
|
|
|
|
|
I find it a lot easier to write a regex that it is to read it. So - to me - copying from the internet and tweaking it sounds hard compared to writing one.
|
|
|
|
|
relatable
Real programmers use butterflies
|
|
|
|
|
Agreed, except when I need it, I pull up the reference and grind through what I need.
I wonder if it would be possible to create an alternate language version of regex, one that is more easy for us regular people to work with, but could then be compiled down to a regex expression. Sort of like TypeScript is for JavaScript. Hmmm, sounds like an interesting project....
|
|
|
|
|
I create Regexes using Visual Studio Code, where we can experiment with the regex and get to see the result on the screen. Learnt about the Regex feature of Visual Studio Code in a Youtube video.
|
|
|
|
|
Unfortunately those tools don't really help me here because of what I'm doing - programmatically simplifying the expression. The whole bug was a brain fart on my part. I knew better. I just wasn't seeing it.
Basically my program was more clever than I was in the moment, and did a simplification I didn't understand at the time.
Real programmers use butterflies
|
|
|
|
|
honey the codewitch wrote: The "bug" was this - I was inputting a regular expression Sounds like a bug alright
Jamie Zawinski wrote: Some people, when confronted with a problem, think
“I know, I'll use regular expressions.” Now they have two problems.
|
|
|
|
|
|
Yeah, but that wasn't my issue.
My issue was I wasn't being as clever as my program was. It found a simplification for my regular expression that I didn't understand at the time even though I should have. It was a prolonged brain fart on my part. It wasn't a knowledge or tools issue. It was just me being a goof. Thanks though!
Real programmers use butterflies
|
|
|
|
|
I think a little Microsoft has rubbed off on you!
"It's not a bug, it's a feature."
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|
|
and not just a feature, but a feature we planned to release 12 years from now.
|
|
|
|
|
|
I've used it before, but it wouldn't have helped me here. My problem was a prolonged brain fart.
I *know* [a-z_A-Z][a-z_A-Z0-9]* will match foo, bar and baz. I was just spacing it off, because I was expecting to see a loop around (foo|ba[rz]) and it was (rightly) eliminating it.
Real programmers use butterflies
|
|
|
|
|
Term: Feature
Definition: A bug with seniority.
|
|
|
|
|
Or Feature: a bug in a sports jacket.
|
|
|
|
|
Undocumented feature.
The less you need, the more you have.
Even a blind squirrel gets a nut...occasionally.
JaxCoder.com
|
|
|
|
|
sometime it is safe to say, the bug exists in human's mind...
diligent hands rule....
|
|
|
|
|
So the real question is…
What happens when you use the second expression as the input to your engine?
Does it return the same value?
|
|
|
|
|
Yes, it does.
Real programmers use butterflies
|
|
|
|
|
Then it must be the correct answer! Stop doubting yourself. 😊
|
|
|
|
|
|
Did you actually listen to the whole thing? I couldn't and I have completion issues. Bailed out at 5 minutes.
I’ve given up trying to be calm. However, I am open to feeling slightly less agitated.
|
|
|
|
|
You lasted longer than me. I think under 2 min for me, lol.
|
|
|
|