Is there a good, online, interactive regex tutorial?

Viewed 25171

Now, I know both SQL and regexes just fine, but a few times on this site, I came across someone working through the exercises on SQLzoo.net. As far as I could tell, this was a wonderful online resource where someone can pretty easily learn SQL by example, writing many toy queries against several toy databases. I will likely redirect people wanting to learn SQL to that site.

These SQLzoo people also run some other tutorials, including some on a few programming languages. However, the section on regular expressions is pretty small (e.g., see Java's page), and I don't think you can actually learn regexes from it. I think a good, online tutorial might help with the onslaught of basic regex questions we have here. (Maybe after the answer, we could suggest that they take a look at the tutorial.)

So, is there a good, online, interactive regex tutorial along the lines of that SQL tutorial? I looked online briefly, but all I could find were non-interactive tutorials or simple pages (still useful, though!) that let you match a string against a pattern so that you could see what it matches/captures/etc.

9 Answers

The site written by @wchung, RegexOne seems to be a perfect answer to the original question. Check that out first ;)

The tool txt2re is, as commenters have rightly mentioned, very ugly. RegExr (ht @runrunraygun) is a much prettier tool for editing regular expressions, although has completely different functionality and still no tutorial.

The main reason it might be useful for learning regexes is the ability to see the effect each edit is having on the matching.

Original answer:

I always thought txt2re was a very clever tool. You just type an example of some text you want to match, and then it lets you pick bits out to match against. I'd consider it to be a fairly useful tool for learning regular expressions.

It's not really interactive, but still a good tutorial: www.regular-expressions.info. You could try combining that tutorial with one of the online RegEx tools to try out the examples (for a little interactivity :-)

It's not online, however, you might enjoy the game RegexExpress (warning: one of the award pictures is nsfw). It's a game made during a PyWeek contest that teaches you to use regex on a curses type interface. I found it quite fun.

There's Regex Hero. It's not a tutorial, but it is interactive. It'll highlight matches as you type. The instant highlighting makes it easy to experiment.

Related