Live data from Hacker News

How "junior" developers can become regex wizards

joshuakemp.blogspot.com

11–20 of 46 posts

Re: How "junior" developers can become regex wizards

#11
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.

Re: How "junior" developers can become regex wizards

#12
post #2

How to become a regular expression wizard: 1. Write a bunch of regular expressions. 2. Fix them when they break. Anybody can do this, however junior they may be. (And yes, it does grant you a superpower.)

Assuredly, like most/anything in life, repetition and dedication will be your regex salvation.

Tools such as this are shortcuts for newcomers to grok the various operators rapidly. I think they are very worthwhile.

Re: How "junior" developers can become regex wizards

#13
post #2

How to become a regular expression wizard: 1. Write a bunch of regular expressions. 2. Fix them when they break. Anybody can do this, however junior they may be. (And yes, it does grant you a superpower.)

3. Write tests.

Don't change your existing regular expressions without tests, or Bad Stuff happens.

Re: How "junior" developers can become regex wizards

#17

Go read Mastering Regular Expressions.

This is the bible of regex. Its explanation of "unrolling the loop" will change how you write regular expressions if you don't already use that technique. Its discussion of the operation of NFA and DFA engines is great too.

Re: How "junior" developers can become regex wizards

#19
post #16

Making "junior" developers solve problems with regex sounds like a recipe for terrible maintainability, unless it is necessary

I do actually somewhat agree here. If one doesn't know what they are doing, it is very easy to do regular expressions incorrectly.

That said, regex is sometimes necessary, so it is important for developers to be competent in this realm. In my opinion, ideally, junior developers would start with using them in non-production environments to become familiar, then go from there. It is also important to be able to distinguish which problems should be solved by regular expressions, and which shouldn't. A good mentor here can be great.

Post reply on HN