They are useful but non-intuitive, so I imagine most people relearn them each time they meet - unless you are stuck doing it all the time.
Is it a must for every programmer to learn regular expressions?
31–40 of 60 posts
Re: Is it a must for every programmer to learn regular expressions?
#32Re: Is it a must for every programmer to learn regular expressions?
#33If you ask "do you personally really need regexps" I'll tell you: don't learn them. As you're asking that question at all, I understand that you're not interested to learn and that you are looking for an excuse not to learn, so do something that interests you.
Re: Is it a must for every programmer to learn regular expressions?
#34Yes, 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…
Hmm - you know I actually think it's not correct to look at regex as an interface - even though we use it as one. It's really more accurate to look at it as a grammar (type 3 if I remember correctly). Anything that comes out of the whole chomskian hierarchy stuff isn't going to look intuitive. But the point is that it is a particular, very rigorously defined system of representation. And various systems of representa…
Why not? Type-0 (recursively enumerable) languages are equivalent to Turing machines, and we've managed to invent some pretty good syntaxes for that. The main problem with regexes really is the syntax. Regular languages are a lot easier to understand (IMO) if you look at the left/right-linear grammars that define the same language as the regex.
Regex syntax as a representation is very close to the FSA used for matching, and that's not necessarily the representation best suited for human consumption.
Re: Is it a must for every programmer to learn regular expressions?
#35However, I try to avoid using them in my code unless they improve readability. Using re.VERBOSE can help in Python.
If you find a regex online, you should definitely reference it in your code, to help provide background understanding, such as validating a UK Post Code.
Re: Is it a must for every programmer to learn regular expressions?
#36Re: Is it a must for every programmer to learn regular expressions?
#37Earlier quoted context omitted.
How would you design a regular expression syntax more intuitively? Personally, I find beauty and simplicity in regular expressions. Sure, they can grow to hideous atrocities, but you can achieve such disastrous feats with any language/syntax. Maybe you could back up your claim of regexes being a disgusting abomination with, at the very least, anecdotal evidence.
A typical regex looks like this: \b[A-Z0-9._%-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\b Which is also what happens when a cat walks across the keyboard.
Re: Is it a must for every programmer to learn regular expressions?
#38Re: Is it a must for every programmer to learn regular expressions?
#39While knowledge how to use regular expression is invaluable, I also recommend learning how they actually work under the hood. It really gives a good lesson when regular expressions are applicable, and when they're not. From my experience, while many programmers are apt in tools like regexps or grammar->parser generators, they very rarely know how it actually works, which results in people trying to parse HTML with re…
Re: Is it a must for every programmer to learn regular expressions?
#40Earlier quoted context omitted.
IMO, the main problem is that the syntax is too terse. The syntax is taken wholesale from the algebraic notation used in mathematics and dropped in unmodified. Essentially, regex code ('cause regexes really are code) is not skimmable. The greatest syntactical atrocity in regexes is that they don't have the `x` modifier (in Perl parlance) on by default. This means that you can't use whitespace to chunk code into meani…
"Easy to write, hard to read". Perl's influence on Regex shows. Which is fine in most cases. I always wonder what regexes would look like if they were derived from Python instead.
It is true that Perl reformed the syntax in important ways (to the better, if you ask me), and later on extended it a lot, but it's certainly not a Perl invention.