View Single Post
Old May 2nd, 2005, 11:44 AM   #6
mackenga
Professional Programmer
 
Join Date: Mar 2005
Location: Glasgow, Scotland
Posts: 317
Rep Power: 4 mackenga is on a distinguished road
If you're already in Perl, why call out to awk? Spydoor's regexp isn't quite there:

my $var = "(02:25:26) user: message";
$var =~ /^\((\d+):(\d+):(\d+)\) (.+?):(.*)$/;
my ($hour, $min, $sec, $user, $msg) = ($1, $2, $3, $4, $5);

I'm pretty sure this ought to work. The regexp was nearly there; I just put a ? after .+ to make it nongreedy (otherwise it would have eaten up the colon and the message) and put anchors on to ensure it would match the whole line.

As usual with code I post, I haven't actually tested it. Ain't I helpful?
mackenga is offline   Reply With Quote