Live data from Hacker News

How "junior" developers can become regex wizards

joshuakemp.blogspot.com

31–40 of 46 posts

Re: How "junior" developers can become regex wizards

#31

Is it worth mastering? No. Worth understanding? Yes. Regex is used in so many applications and commands, it would be silly not to learn it. You don't need to be a wizard, but do understand the basics and it will get you far.

That depends. The skills I developed with sed and awk have paid dividends. But when I hear someone speak of becoming a regex master, as if a regex was an entire tool unto itself and not just a way of representing a pattern, that makes me think of Perl regexes in all their absurdity.

Re: How "junior" developers can become regex wizards

#32
Also, check for your language's options for white space and comments within regular expressions [0]. Regexps don't have to be blobs of characters -- you can use white space to make them more readable and use comments embedded within a multi-line regexp to describe what/why you are doing.

Bonus: it makes them easier to diff, too!

We don't write our code on one line with no comments, writing regexps should be no different.

[0] Python example: http://docs.python.org/2/library/re.html#re.VERBOSE

Re: How "junior" developers can become regex wizards

#34
post #4

This might be overkill but I found I never "got" regular expressions until a class made me think about them as state machines. The additional bashing over the head of having to implement a parser/matcher made it really stick. The quirks and syntax make much more sense when you know why and how a regex engine works. That said, anything involving extended/perl regex I wind up googling.

Huh, to me I "got" regexp the first time I used it (although it took a while to learn the details). To me if you understand the idea of wildcards, you understand regexp.

Re: How "junior" developers can become regex wizards

#35

Is it worth mastering? No. Worth understanding? Yes. Regex is used in so many applications and commands, it would be silly not to learn it. You don't need to be a wizard, but do understand the basics and it will get you far.

Somewhere in between "the basics" and "wizard" is probably best. Regexp is powerful, extremely valuable in the right places, and knowing more than the basics will be useful. On the other hand wizard-level expertise is not necessary to net 99% of the value of regexp.

Re: How "junior" developers can become regex wizards

#37
post #5

A couple things: 1. Be careful what you use regex's for. Email addresses are very difficult[0]. HTML is impossible[1]. 2. There are a number of tools that make it easier to understand, including [2]. [0] http://www.ex-parrot.com/pdw/Mail-RFC822-Address.html [1] http://stackoverflow.com/a/1732454/2363 [2] http://ivanzuzak.info/noam/webapps/fsm_simulator/

> HTML is impossible. This comes up a lot. Most languages' "regular expressions" aren't, in fact, regular. A true regular expression wouldn't be able to match HTML, but Perl regular expressions (the de facto standard) can because of backreferences. Edit: I'm not saying this is a good idea; it most certainly isn't. I'm just saying its possible.

Perl's regex support can match HTML because of recursive matching, not only because of backreferences (the latter of which is widely implemented, the former not quite so).

That being said, there surely are some fun languages that can be matched by what's commonly called regular expressions. Notepad++ was notable (before switching to PCRE) that its "regular expressions" could not even match every regular (or even finite) language (http://stackoverflow.com/a/4815422/73070). Many regex engines allow matching languages that are context-sensitive, while at the same time not accepting all context-free languages.

Re: How "junior" developers can become regex wizards

#38
I found http://www.regular-expressions.info/ to be an invaluable resource when learning or understanding regular expressions. Basically every page that explains a feature in the reference also explains what's going on within the engine, how it works, when it backtracks, etc. Those things are sometimes hard to see in applications that just give you the matches from a text (as rubular.com seems to do).

Re: How "junior" developers can become regex wizards

#39
post #4

This might be overkill but I found I never "got" regular expressions until a class made me think about them as state machines. The additional bashing over the head of having to implement a parser/matcher made it really stick. The quirks and syntax make much more sense when you know why and how a regex engine works. That said, anything involving extended/perl regex I wind up googling.

Huh, to me I "got" regexp the first time I used it (although it took a while to learn the details). To me if you understand the idea of wildcards, you understand regexp.

I began to understand Regex after reading the awk chapter in Masterminds of Programming. After that I understood how "the machine" inside might work. I really understood how to apply Regex to single strings after I started to see a regex as a "mask", so very similar to your wildcard approach.
Post reply on HN