Is it a must for every programmer to learn regular expressions?
51–60 of 60 posts
Re: Is it a must for every programmer to learn regular expressions?
#52Yes, it is, without a doubt. It's one of the most universal tricks of the trade that you'll literally never regret learning, mainly because just about any environment you'll ever work in will by necessity support regexes, and in many, it will be the primary way you interact with text. But it's also a must that you realize that despite the fact that they're exceptionally useful and widely supported, regexes are a disg…
I think the real problem is that we lack (or don't learn) good tools to bridge the gap between regular expressions and 'custom parser'. We're reluctant to refactor from '1 line of just-starting-to-be-horrible regex' to tens or hundreds of lines (depending on language and libraries) to do it 'properly', and so we end up stretching regular expressions beyond the point where they make life easier.
Perl has Parse::RecDescent (and probably several others), which is pretty close to the right thing, and clearly it's very doable in a lot of languages - anyone got any suggestions in other languages?
Re: Is it a must for every programmer to learn regular expressions?
#53Also if you are familiar with this quote:
"Some people, when confronted with a problem, think
'I know, I'll use regular expressions.' Now they have two problems."
Read Jeffrey Friedl's research into the quote - http://regex.info/blog/2006-09-15/247Re: Is it a must for every programmer to learn regular expressions?
#54Learn the 20% that you will use 80% of the time. If your not willing to do that your probably not serious about programming in the first place.
[i]
Many don't know the difference nor implications of .* ? vs .*And on and on. It amazes me that these people actually code for a living.
Re: Is it a must for every programmer to learn regular expressions?
#55"Regular expressions are hard to write, hard to write well, and can be expensive relative to other technologies... Standard lexing and parsing techniques are so easy to write, so general, and so adaptable there's no reason to use regular expressions.
"Another way to look at it is that lexers and parsing are matching statically-defined patterns, but regular expressions' strength is that they provide a way to express patterns dynamically. They're great in text editors and search tools, but when you know at compile time whatall the things are you're looking for, regular expressions bring far more generality and flexibility than you need.
"Encouraging regular expressions as a panacea for all text processing problems is not only lazy and poor engineering, it also reinforces their use by people who shouldn't be using them at all."
http://commandcenter.blogspot.com/2011/08/regular-expression...
http://news.ycombinator.com/item?id=2915137
Personally, I think they're pretty darn useful and too powerful to not learn, but Pike's comment makes me think that maybe they're also a crutch that I've relied on too much rather than learning enough about lexing/parsing.
Re: Is it a must for every programmer to learn regular expressions?
#56Earlier quoted context omitted.
[1] Thinking of embedded systems developers creating code for, say, automotive entertainment systems, or control code for scientific or medical hardware. Don't they have log files to read?
That's what grep is for ;-) But the point is I can't imagine someone getting to that point without previously having learned it.
Re: Is it a must for every programmer to learn regular expressions?
#57Earlier quoted context omitted.
That's what grep is for ;-) But the point is I can't imagine someone getting to that point without previously having learned it.
Err, grep uses regular expressions.
Re: Is it a must for every programmer to learn regular expressions?
#58Yes, it is, without a doubt. It's one of the most universal tricks of the trade that you'll literally never regret learning, mainly because just about any environment you'll ever work in will by necessity support regexes, and in many, it will be the primary way you interact with text. But it's also a must that you realize that despite the fact that they're exceptionally useful and widely supported, regexes are a disg…
Of course, you would also have to be able to nest these for more advanced matching...
Is there something like this already in existence? :)
Re: Is it a must for every programmer to learn regular expressions?
#59Yes, it is, without a doubt. It's one of the most universal tricks of the trade that you'll literally never regret learning, mainly because just about any environment you'll ever work in will by necessity support regexes, and in many, it will be the primary way you interact with text. But it's also a must that you realize that despite the fact that they're exceptionally useful and widely supported, regexes are a disg…
I could imagine a Jquery-like DSL where something like /^[A-Z]+[0-9]{2}$/ could be expressed like Match(str).BeginsWith().BigCaseAlpha().AtLeastOne().Numeric().FixedLength(2).EndsWith() Of course, you would also have to be able to nest these for more advanced matching... Is there something like this already in existence? :)
Re: Is it a must for every programmer to learn regular expressions?
#60Learn the 20% that you will use 80% of the time. If your not willing to do that your probably not serious about programming in the first place.
Amen to that. For reasons I can only guess at, I'm the "regex guy" at work. When people have a regex question they come to me. And the interesting thing is that the answers are not hard, well within the 20% area. I've found that most people don't care to learn how to use character classes, or even what they're for. For example, to match the single letter 'i', I've seen people write: [i] Many don't know the difference…