views:

1252

answers:

5

I learned a lot of Perl RegEx syntax rules, but probably the only way to actually be able to write them is to do a bunch of 'RegEx' related exercises.

I looked over the other "Learn RegEx" threads on StackOverflow, but haven't found anything similar.

Is there any collection of such exercises? In form of book, HTML, with/without answers, it doesn't matter, just to keep me writing RegExes for a while.

+1  A: 

Try HTML page scraping. Scanning HTML (that is not always well-formed) is a great way to hone your regex skills. I'd suggest finding pages with multiple items and writing a script that will turn them into a summary or RSS feed.

Tautologistics
Having writen some 15 line regular expressions recently to do just this, I have to agree. :)
cletus
+3  A: 

I suggest browsing the regex tagged questions on this site and experiment with your own answers without peaking at the current ones. You don't need to post your answers, but I bet that sometimes you'll come up with answers that are worth publishing.

Three good things with this approach:

  1. You'll be working with real-world problems.
  2. You might learn stuff about other programming languages as you go. ('Tis always good to learn new languages).
  3. You probably will be helping the world find good answers to real world regex questions.
PEZ
+1 I haven't found what I looked for, but this is closest match :)
Jox
+4  A: 

My books Learning Perl and Learning Perl Student Workbook each have regular expression exercises and answers.

brian d foy
Brian, I'm reading "Learning Perl" 5th, and I know about exercises, but, I need more (complex) exercises... Only 5-8 per chapter (that makes only ~20 for RegEx, and these are pretty basic.
Jox
A: 

Just check out the source for Regexp::Common:

http://search.cpan.org/~abigail/Regexp-Common-2.122/lib/Regexp/Common.pm

Bill
+2  A: 

Work through Mastering Regular Expressions, playing with each new construct introduced: it'll teach you everything you ever wanted to know, and even stuff you didn't.

rpj