I personally use Emacs' regex-builder mode to get quick visual feedback on what a pattern matches on a given input data before I set it loose. (regex-coach is Perl compatible but emacs is not; I frequently type [0-9]+ in emacs to mean \d+)
For me, none of this cleverness really solves the problem that regular expressions represent for building a large application.
For example, I found code that generates expressions like "(^|)Terminal(|)" in running mono code in a project I'm working on. I have played with REs a fair amount and I don't know exactly what this should do or why. But it's been doing it for a while.
Sorry, but most Regexing should be avoided unless you have a really good reason. Use system calls to parse file paths, use a really parser to parse a DSL, and so-forth.
The biggest problem I have with regular expressions is all the differences in syntax between java, ruby, grep etc. I find that I could use them about every other week but I have to go and google for how to use them in each environment. It isn't just the difference between how to say "match digits" but in java you use a few lines of oo code whereas in ruby there is an operator ~= to match or replace.
Then oracle started to support them in one of the more recent releases. So that is yet another syntax/api to learn.
I find I can remember how to do the basic searches but for anything more advanced I have to spend a while debugging it.
Honestly, if you are a "Regular" programmer, then RegEx would not be a problem in the first place. Without them, you are more of a "stunted" programmer.
I agree with most of what you had to say. I do not, however, agree with the first part of your comment. A lot of gifted programmers simply have no real need to use regular expressions, especially if they develop primarily in Java. This is just unfortunate for them, as they end up not learning them at all. This doesn't necessarily mean they are "stunted", but just unlucky.
I don't understand what is difficult about regular expressions. Yes they are cryptic, but they are very straight forward when you understand the syntax. At work I have become the goto guy for all things regular expression related. The developers that ask me for Regex help are not junior programmers either. Maybe the cryptic nature of regex just turns people off or scares them.
17 comments
[ 3.3 ms ] story [ 37.8 ms ] threadhttp://weitz.de/regex-coach/
I personally use Emacs' regex-builder mode to get quick visual feedback on what a pattern matches on a given input data before I set it loose. (regex-coach is Perl compatible but emacs is not; I frequently type [0-9]+ in emacs to mean \d+)
http://www.gskinner.com/RegExr/
http://regex.powertoy.org
For example, I found code that generates expressions like "(^|)Terminal(|)" in running mono code in a project I'm working on. I have played with REs a fair amount and I don't know exactly what this should do or why. But it's been doing it for a while.
Sorry, but most Regexing should be avoided unless you have a really good reason. Use system calls to parse file paths, use a really parser to parse a DSL, and so-forth.
Far better than cludges and crutches is a good RegEx tester, for example: http://www.regextester.com/
Put in the real deal. Put in what you expect to match, and tweak until you get it right and understand why it wasn't working before.