[oak perl] Regular Expressions

David Wheeler david at kineticode.com
Thu Mar 11 10:43:57 CST 2004


On Mar 10, 2004, at 12:55 PM, Tony Stubblebine wrote:

> I'm curious to see what sort of regular expressions people are 
> writing, good and bad. And I'd love to start a discussion on regex 
> style or technique.

Here's the most complex regex I've written to date. I use it in 
activitymail to parse out the file name and revision numbers from the 
file list passed to CVS commits.

     my $regex = qr/^(.*?)(?:,([\d.]+.\d|NONE))?(?:,([\d.]+.\d|NONE))?$/;

The file list spec from CVS can look like these:

   no.gmo,NONE,1.1.2.1
   no.po,1.1.2.1,NONE
   tr.gmo,1.13,1.13.4.1
   tr.po,1.13,1.13.4.1

It's used like this:

         my ($file, $old, $new) = $spec =~ $regex;

Ugly, ain't it? It does the trick, though.

Regards,

David




More information about the Oakland mailing list