On 5/7/06, Dan <[EMAIL PROTECTED]> wrote:
i been doing perl long enough that you'd think i should know this, but one
thing i've never ever ever managed to get my head around is how regex works.
i'm using net::pop3 (mail::pop3client doesn't work!), and i'm trying to
extract certain data from the pop3 stream (from, subject, and some of the
body eventually). but the regex behind matching the line required is just
baffling me. i could cheat and say
if (substr($line,0,5) eq "From:") { }, but i want to get past the phase of
doing things the such a long way round, and learn more about regex.
i wrote a program some months back which utilised a compelx regex sub
$onchan{lc($data[0])} =~ s/(,|^)\Q$data[1]\E(?=,|$)//;
which substitutes the exact match for $data[1] in a long string which is
csv, and replace it with nothing. i'm trying to use the same routine, or the
same method, to get the 'dan' out of
"dan" [EMAIL PROTECTED]
but a) the regex confuses me enough to not know how to get that out of there
(i've replaced the ,'s with "'s, but that's obviously not enough), and b) i
don't know how to give the regex the full line of text, and assign the
extracted value into a variable for use later on.
i'd really like to get my head round this. if anyone's got any good guides,
pointers, or places i can go to read and help me learn more, i'd much
appreciate it.
many thanks.
dan
Not to clear on what this means:
to get the 'dan' out of "dan" [EMAIL PROTECTED]
But here's a stab...
my $string = '[EMAIL PROTECTED]';
$string =~ s/^(.*?)@//;
This would actualy return "@domain.com";
If you want the username, then:
my ($username) = $string =~ m/^(.*?)@/;
if (substr($line,0,5) eq "From:") { }, but i want to get past the phase of
if ($line =~ m/^From:/i) { do something with "From" line; }
--
Anthony Ettinger
Signature: http://chovy.dyndns.org/hcard.html
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>