in reply to A little regex help please!

More of the same, but

local $/; my $text = <DATA>; my ($number, $from) = $text =~ /mailbox (\d+).*?From:\s*([^\n]+)/;

It might be more efficient to replace the .*? with .*. Both will work.

Replies are listed 'Best First'.
Re^2: A little regex help please!
by japhy (Canon) on Jan 31, 2006 at 22:03 UTC
    /.*?\n/ isn't really any slower, since it jumps to the closest newline it finds. The silly thing is the ? in that regex. The .*? in your regex WON'T match over the newlines, so you're missing an /s modifier I think. And since [^\n] IS ., I'd just write:
    { local $/; my ($num, $from) = <FILE> =~ m{ mailbox \s+ (\d+): \s+ From: \s* (.*) }x; }
    Untested, but it seems to me that it should work properly, given the data from the OP.

    Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
    How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart