Live data from Hacker News

Learn RegEx step by step, from zero to advanced

regexlearn.com

41–50 of 114 posts

Re: Learn RegEx step by step, from zero to advanced

#41

Earlier quoted context omitted.

It's really subject-specific. What I usually see is a small problem easily solved by Regex, that a few months later down the line we need to expand the regex a little bit, but that's ok it's still readable... repeat this a bunch of times and now you have a critical regex line that nobody really understands how it works and nobody ever wants to touch without it being unit-tested to death. It's just a riff on tech-debt…

We need a natural-language regex translator

Back when I used Windows, I had an app called Regex Buddy and you could paste in any regex and it would generate a comment block that broke down what was going on. Was super useful when you come back a few months later and need to understand a complex regex

Re: Learn RegEx step by step, from zero to advanced

#42
post #8

>Regular Expressions, abbreviated as RegEx or RegExp, are a string of characters created within the framework of RegEx syntax rules. You can easily manage your data with RegEx, which uses commands like finding, matching, and editing. Regex can be used in programming languages such as Phyton, SQL, Javascript, R, Google Analytics, Google Data Studio, and throughout the coding process. Learn regex online with examples a…

I think regex is absolutely terrible garbage. It’s very powerful, I do appreciate not having to write complex conditional statements, and it’s great that it’s available is so many languages and applications. But it’s just a bad tool, terribly unreadable, easy to introduce bugs, with lots of trial and error. It has too much brevity and would be much better if it were longer but more human readable. I’m sure there are…

You can get a feel for what that would look like here: https://metacpan.org/release/CHROMATIC/Regexp-English-1.01/v...

But then you're just memorizing things like 'start_of_line' instead of '^'. Perhaps easier to read, but no easier to write.

Re: Learn RegEx step by step, from zero to advanced

#43

I learn regex just before I need it. Every. Time. After 25 years, it just doesn't stick.

Why use it though? I'd rather wright or read 30 lines of code instead of trying to decipher what a regex means or do and making sure it is covering all possible cases. I don't understand the goodwill toward regexes. It's basically an embedded BrainFuck in your programming language. I'm 14 years in my dev career, there never was a moment where not using regexes came to be a problem.

> Why use it though?

Because a well written regex performs extremely well (regex engines are often very highly optimized).

It gives you all the benefits of using a domain-specific language and using an extremely mature software library. Just like a domain-specific language, it will have a baked-in philosophy involving the exact task you want to accomplish, so it will not suffer from language vs algorithm impedence. Just like using a mature library, it will probably have accounted for weird oddball cases that you're not even thinking of and have enough features to do everything you will want.

> It's basically an embedded BrainFuck in your programming language.

I don't disagree. It's not easy to read and can be hard to maintain. There are ways to write regex such that it's easier to understand, but the syntax generally doesn't make it easy to do that and doesn't encourage you to spend the time on it.

However, when you see a regex, you do know that it's 100% used to manipulate strings. That alone tells you quite a bit about what is going on.

Re: Learn RegEx step by step, from zero to advanced

#45
post #8

>Regular Expressions, abbreviated as RegEx or RegExp, are a string of characters created within the framework of RegEx syntax rules. You can easily manage your data with RegEx, which uses commands like finding, matching, and editing. Regex can be used in programming languages such as Phyton, SQL, Javascript, R, Google Analytics, Google Data Studio, and throughout the coding process. Learn regex online with examples a…

> I always look at these intros/descriptions of Regex with a heavy heart. They describe what regex's are, but none of the info is going to make much sense to someone who doesn't already know why they would want to learn them. > Catch 22 of trying to explain what they are. any teachers, or people who explain/document things for a living, have some good tips or templates to avoid this?

Doesn't make sense to me.

> Regular expressions (commonly known as "regex") are used for advanced pattern matching in strings. They can also be used to replace text, transform strings, or extract substrings. It's a very powerful domain-specific language that is purpose-built for string patterns and manipulation. Many general-purpose programming languages include regex engines that use similar, but often slightly different syntaxes to support the use of regex.

Re: Learn RegEx step by step, from zero to advanced

#46
post #40
post #37

Earlier quoted context omitted.

It very much depends what the use case is. I find that a lot of the text processing I do is easier to use back references or other regexy things. Having said this, I use tools that make regexes easy to use and readily available - I think in many programming languages the syntax means that other solutions are just as easy to devise and implement.

If you are a solo dev, you do you, but if you are working in a team and you are building huge regexes with back references and other bells and whistles... I would guess it's not very readable for your teammates. At least for me, when I look at such a regex I have to stare at it for minutes before grokking it.

I wonder if there's a metric for code reviews measuring mean-time-to-grok (MTTG).

Re: Learn RegEx step by step, from zero to advanced

#47

I learn regex just before I need it. Every. Time. After 25 years, it just doesn't stick.

I was excellent at regex early in my career... actually had a job where that's basically all I did for 9 months. Read the O'Reilly book Mastering Regular Expressions from cover to cover and referenced it multiple times per day. Doing regex at a high level was instinctual. Lost much of that knowledge within a couple years after leaving that job... was shocked how much wasn't retained when I stumbled into another proje…

In fairness, I don't think I was ever a heavy user quite like you describe but if I take another language that I knew well and now dip into every so often - like C - I'm going again in 5 minutes. I don't find that with regex. I do try ... I think it's cool but it just slides straight out.

Re: Learn RegEx step by step, from zero to advanced

#48

I learn regex just before I need it. Every. Time. After 25 years, it just doesn't stick.

I simply don't want to memorize 3 or more different versions of the syntax codes. Sometimes I'm using .Net. Sometimes I'm using Python. Sometimes I'm using whatever oddball engine the developer chose. I know how regex works. I can use forward and backward references. I can combine complex patterns. I can match, extract, replace, transform, etc. Sometimes I have even used nested patterns (though I'd probably need half…

I agree. Regex for me is particularly slippery - I haven't needed to code 68000 assembler since 2002 but I had a play with an emulator last month and slipped back into it. There's something about the syntax that my brain just can't hold onto.

Re: Learn RegEx step by step, from zero to advanced

#49

I learn regex just before I need it. Every. Time. After 25 years, it just doesn't stick.

I have some basics down pat (., +, *, ?, ^, $, [], [^], (), \d) and anything more I always have to look up (and much of it differs between engines anyway). Usually, though, what takes more time to figure out than the regex itself is whatever unholy combination of escaping rules is in force in the place where I have to use it.

I'm with you - if I'm doing a quick find/replace in VSCode then I can usually muddle a way through but anything more complex leaves me somewhat at a loss.

Re: Learn RegEx step by step, from zero to advanced

#50

Earlier quoted context omitted.

It's really subject-specific. What I usually see is a small problem easily solved by Regex, that a few months later down the line we need to expand the regex a little bit, but that's ok it's still readable... repeat this a bunch of times and now you have a critical regex line that nobody really understands how it works and nobody ever wants to touch without it being unit-tested to death. It's just a riff on tech-debt…

We need a natural-language regex translator

I am a huge, huge fan of https://regexper.com/ - paste pretty much any regex, and it will generate a visualization of what it does. It's been invaluable even just as a sanity check, it just makes it so easy to trace the flow of what a pattern is doing.
Post reply on HN