in reply to A little regex help please!

Lookahead assertion
#!/usr/bin/perl -w use strict; local $/; my $line = <DATA>; if($line=~m/(\d+):\s+From:\s+(.*?)(?=Length)/s){ print $1 . $2; } 1; __DATA__ There is a new voicemail in mailbox 11234567890: From: "Unknown" <Unknown> Length: 0:13 seconds Date: Thursday, January 19, 2006 at 11:35:01 AM
Prints:
perl hate.pl 11234567890"Unknown" <Unknown>

Update:Okay, I have to ask it...how in the hell did you go 10 years coding in Perl without learning regexes?

Celebrate Intellectual Diversity

Replies are listed 'Best First'.
Re^2: A little regex help please!
by jdtoronto (Prior) on Feb 01, 2006 at 05:25 UTC
    Well, going ten years without learning regexes is pretty hard! I have a little 'cookbook' of regex formulae, I have every Perl book worth having, and a few that are worth nothing and much of the time I can work out the basics. If you really want to know the sad truth I am a mathematician who hd a heart attack at age 36 (I am not 52) and there are some areas in which I was most proficient which now baffle me totally. Other things i have no trouble with at all! Go figure.

    jdtoronto

Re^2: A little regex help please!
by blazar (Canon) on Feb 01, 2006 at 11:18 UTC
    Update:Okay, I have to ask it...how in the hell did you go 10 years coding in Perl without learning regexes?

    Wild guess: much fiddling with index and substr, and occasionally pack and unpack?
    ;-)