Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I agree that people should learn how regular expressions work. They should also learn how SQL works. People get scared of these things, then hide them behind an abstraction layer in their tools, and never really learn them.

But, more than most tools, it is important to learn what regular expressions are and are not for. They are for scanning and extracting text. They are not for parsing complex formats. If you need to actually parse complex text, you need a parser in your toolchain.

This doesn't necessarily require the hair pulling that the article indicates. Python's BeautifulSoup library does a great job of allowing you convenience and real parsing.

Also, if you write a complicated regular expression, I suggest looking for the /x modifier. You will have to do different things to get that. But it allows you to put comments inside of your regular expression. Which turns it from a cryptic code that makes your maintenance programmer scared, to something that is easy to understand. Plus if the expression is complicated enough, you might be that maintenance programmer! (Try writing a tokenizer as a regular expression. Internal comments pay off quickly!)



Yeah but you also learn a tool’s limitations if you sit down and learn the tool.

Instead people are quick to stay fuzzy about how something really works so it’s a lifetime of superstition and trial and error.

(yeah it’s a pet peeve)




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: