Live data from Hacker News

Learn RegEx step by step, from zero to advanced

regexlearn.com

31–40 of 114 posts

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

#31

  [0] Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems.
I love regular expressions and figuring out the syntax to solve problems I encounter where I can use regex. Such as searching code for calls with specific named params that may be in different order across the code base. But I always have this quote in the back of my mind if I'm thinking about using regex in code, especially areas that get hit a lot.

[0] https://blog.codinghorror.com/regular-expressions-now-you-ha...

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

#32

[0] Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems. I love regular expressions and figuring out the syntax to solve problems I encounter where I can use regex. Such as searching code for calls with specific named params that may be in different order across the code base. But I always have this quote in the back of my mind if I'm thinking about us…

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, imho

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

#33
I find it hard to appreciate the need for this website. First, after scrolling down to the bottom of the page, I still couldn't see where I could "start". I clicked the only prominent button featured on the page, "Product Hunt", and that took me to a clearly unrelated website. You'd think the green words "learn, practice, test, share" would be links, but nope. So after 30+ seconds of browsing it still isn't clear to me where the product was. I gave up.

Compare that with https://regexone.com/ . No fluff. I immediately know what I'm looking at and am given a simple practice problem, with a place to type smack in the middle of the page, and a responsive green coloring when I get something right. The problems advance to exactly the kind of stuff I need, with a quick view on all the lessons on the right-hand side. I'm visiting that website for the n^th time because I need to quickly refresh my regex to accomplish a task.

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

#34
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 other string search paradigms that are far better but relatively unknown.

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

#35

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.

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

#36

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.

I think it's case-by case. I once scraped a list of names and dates from individual Wikipedia pages. There were lots of formats like "1900-1950", "1900 - 1950", "(1900 - 1950)", "(1900 to 1950)", "1900 to cf. 1950", and so on. These were arbitrarily nested in the first couple sentences.

My thought was "Oh I think this is a job for that regex thing" and 35 minutes of googling syntax + a handful of passes later I had all the dates in a workable table. I have no idea how much code that would have taken. Albeit, I am a novice programmer.

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

#37
post #20
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…

Regex is powerful but I've found like 90% of the time I encounter one it would have been far simpler and more readable to use find + substring indexing or string splitting. Imo replacing several nested if statements with a single esoteric regex is not necessarily a win. It depends on if pattern matching is really the best tool for the job.

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.

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

#38

[0] Some people, when confronted with a problem, think "I know, I'll use regular expressions." Now they have two problems. I love regular expressions and figuring out the syntax to solve problems I encounter where I can use regex. Such as searching code for calls with specific named params that may be in different order across the code base. But I always have this quote in the back of my mind if I'm thinking about us…

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

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

#40
post #37
post #20

Earlier quoted context omitted.

Regex is powerful but I've found like 90% of the time I encounter one it would have been far simpler and more readable to use find + substring indexing or string splitting. Imo replacing several nested if statements with a single esoteric regex is not necessarily a win. It depends on if pattern matching is really the best tool for the job.

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.
Post reply on HN