FAQ
OK, I'm an idiot. I just cannot get a simple regex match to work as
intended. I've google, I dug out my books of regex and Perl but I hang
my head in shame and ask here for help;

Take This line;

Jun 14 08:14:41 pingpong postfix/smtpd[22386]: NOQUEUE: reject: RCPT
from host120-109-dynamic.56-82-r.retail.telecomitalia.it[82.56.109.120]:
554 5.7.1 <[email protected]>: Sender address rejected: spoofing of
domain; from=<[email protected]> to=<[email protected]> proto=SMTP
helo=<82.56.109.120>

I'm trying to grab the email address in the 'from=<...' portion. I can
pin this down with look ahead look behind;

(?(?=>)

But it has a side effect of going to the last > on the line, not the
closing half of the pair <>.

To knock out the complications I drop to a simple pattern without the
look ahead/behind;

<.+\@.+>

again it matches all the way to the end of the line, not just the
opening < and closing > as intended.


Now, a little research and I come up with 'greedy -v- non greedy'
matching and thought I was on to something. But I can get that to play
ball either;

(.*?)>

But No dice. After 8 hours on this I'm starting to kick myself blue. Can
anyone put me out of my misery?

Search Discussions

  • John W. Krahn at Jun 21, 2009 at 2:16 pm

    EASY buzzhost.co.uk wrote:
    OK, I'm an idiot. I just cannot get a simple regex match to work as
    intended. I've google, I dug out my books of regex and Perl but I hang
    my head in shame and ask here for help;

    Take This line;

    Jun 14 08:14:41 pingpong postfix/smtpd[22386]: NOQUEUE: reject: RCPT
    from host120-109-dynamic.56-82-r.retail.telecomitalia.it[82.56.109.120]:
    554 5.7.1 <[email protected]>: Sender address rejected: spoofing of
    domain; from=<[email protected]> to=<[email protected]> proto=SMTP
    helo=<82.56.109.120>

    I'm trying to grab the email address in the 'from=<...' portion. I can
    pin this down with look ahead look behind;

    (?(?=>)

    But it has a side effect of going to the last > on the line, not the
    closing half of the pair <>.

    To knock out the complications I drop to a simple pattern without the
    look ahead/behind;

    <.+\@.+>

    again it matches all the way to the end of the line, not just the
    opening < and closing > as intended.


    Now, a little research and I come up with 'greedy -v- non greedy'
    matching and thought I was on to something. But I can get that to play
    ball either;

    (.*?)>

    But No dice. After 8 hours on this I'm starting to kick myself blue. Can
    anyone put me out of my misery?
    You need to make both sides of @ non-greedy:

    (?(?=>)

    Or:

    <.+?\@.+?>




    John
    --
    Those people who think they know everything are a great
    annoyance to those of us who do. -- Isaac Asimov
  • Richard at Jun 21, 2009 at 2:20 pm

    On Sun, 2009-06-21 at 07:16 -0700, John W. Krahn wrote:
    EASY buzzhost.co.uk wrote:
    OK, I'm an idiot. I just cannot get a simple regex match to work as
    intended. I've google, I dug out my books of regex and Perl but I hang
    my head in shame and ask here for help;

    Take This line;

    Jun 14 08:14:41 pingpong postfix/smtpd[22386]: NOQUEUE: reject: RCPT
    from host120-109-dynamic.56-82-r.retail.telecomitalia.it[82.56.109.120]:
    554 5.7.1 <[email protected]>: Sender address rejected: spoofing of
    domain; from=<[email protected]> to=<[email protected]> proto=SMTP
    helo=<82.56.109.120>

    I'm trying to grab the email address in the 'from=<...' portion. I can
    pin this down with look ahead look behind;

    (?(?=>)

    But it has a side effect of going to the last > on the line, not the
    closing half of the pair <>.

    To knock out the complications I drop to a simple pattern without the
    look ahead/behind;

    <.+\@.+>

    again it matches all the way to the end of the line, not just the
    opening < and closing > as intended.


    Now, a little research and I come up with 'greedy -v- non greedy'
    matching and thought I was on to something. But I can get that to play
    ball either;

    (.*?)>

    But No dice. After 8 hours on this I'm starting to kick myself blue. Can
    anyone put me out of my misery?
    You need to make both sides of @ non-greedy:

    (?(?=>)

    Or:

    <.+?\@.+?>




    John
    --
    Those people who think they know everything are a great
    annoyance to those of us who do. -- Isaac Asimov
    John. I love you. I want to have your Babies. Thank you soo much!
    I don't understand WHY I have to do that, but it works and at this
    moment that is good enough for me!

    THANK YOU SIR!
  • Chas. Owens at Jun 22, 2009 at 11:45 am

    On Jun 21, 2009, at 10:19, "[email protected]" wrote:
    On Sun, 2009-06-21 at 07:16 -0700, John W. Krahn wrote:
    EASY buzzhost.co.uk wrote:
    OK, I'm an idiot. I just cannot get a simple regex match to work as
    intended. I've google, I dug out my books of regex and Perl but I
    hang
    my head in shame and ask here for help;

    Take This line;

    Jun 14 08:14:41 pingpong postfix/smtpd[22386]: NOQUEUE: reject: RCPT
    from host120-109-dynamic.56-82-r.retail.telecomitalia.it
    [82.56.109.120]:
    554 5.7.1 <[email protected]>: Sender address rejected: spoofing of
    domain; from=<[email protected]> to=<[email protected]> proto=SMTP
    helo=<82.56.109.120>

    I'm trying to grab the email address in the 'from=<...' portion. I
    can
    pin this down with look ahead look behind;

    (?(?=>)

    But it has a side effect of going to the last > on the line, not the
    closing half of the pair <>.

    To knock out the complications I drop to a simple pattern without
    the
    look ahead/behind;

    <.+\@.+>

    again it matches all the way to the end of the line, not just the
    opening < and closing > as intended.


    Now, a little research and I come up with 'greedy -v- non greedy'
    matching and thought I was on to something. But I can get that to
    play
    ball either;

    (.*?)>

    But No dice. After 8 hours on this I'm starting to kick myself
    blue. Can
    anyone put me out of my misery?
    You need to make both sides of @ non-greedy:

    (?(?=>)

    Or:

    <.+?\@.+?>




    John
    --
    Those people who think they know everything are a great
    annoyance to those of us who do. -- Isaac Asimov
    John. I love you. I want to have your Babies. Thank you soo much!
    I don't understand WHY I have to do that, but it works and at this
    moment that is good enough for me!

    THANK YOU SIR!


    --
    To unsubscribe, e-mail: [email protected]
    For additional commands, e-mail: [email protected]
    http://learn.perl.org/
    It is easier to see why with a shorter example:

    #!/usr/bin/perl

    use strict;
    use warnings;

    my $s = "123456";

    print
    "greedy:\n", (map { "\t$_\n" } $s =~ /(.+)(.)(.+)/),
    "partial:\n", (map { "\t$_\n" } $s =~ /(.+?)(.)(.+)/),
    "non greedy:\n", (map { "\t$_\n" } $s =~ /(.+?)(.)(.+?)/);

    The non-greedy modifier (?) causes the regex engine to look for the
    shortest string (starting from the current position) that matches.
    So, when the match is greedy, the first period consumed all but the
    last two characters (because otherwise it would not have matched).
    When the first period is made non-greedy, it consumes one character,
    then the second period matches, and, finally, the third consumes the
    rest. In the last example all three match just one character.
  • Gurunandan R. Bhat at Jun 21, 2009 at 2:20 pm
    I am sure that someone will write a regex for you that will work.
    However, why not use Mail::Log::Parse::Postfix (this is a Postfix log
    right?) and getting the parameters you want is as easy as
    $logline->{to} .. well almost :)

    Regards
    Gurunandan




    On Sun, 2009-06-21 at 14:54 +0100, EASY buzzhost.co.uk wrote:

    OK, I'm an idiot. I just cannot get a simple regex match to work as
    intended. I've google, I dug out my books of regex and Perl but I hang
    my head in shame and ask here for help;

    Take This line;

    Jun 14 08:14:41 pingpong postfix/smtpd[22386]: NOQUEUE: reject: RCPT
    from host120-109-dynamic.56-82-r.retail.telecomitalia.it[82.56.109.120]:
    554 5.7.1 <[email protected]>: Sender address rejected: spoofing of
    domain; from=<[email protected]> to=<[email protected]> proto=SMTP
    helo=<82.56.109.120>

    I'm trying to grab the email address in the 'from=<...' portion. I can
    pin this down with look ahead look behind;

    (?(?=>)

    But it has a side effect of going to the last > on the line, not the
    closing half of the pair <>.

    To knock out the complications I drop to a simple pattern without the
    look ahead/behind;

    <.+\@.+>

    again it matches all the way to the end of the line, not just the
    opening < and closing > as intended.


    Now, a little research and I come up with 'greedy -v- non greedy'
    matching and thought I was on to something. But I can get that to play
    ball either;

    (.*?)>

    But No dice. After 8 hours on this I'm starting to kick myself blue. Can
    anyone put me out of my misery?


  • EASY buzzhost.co.uk at Jun 21, 2009 at 3:58 pm

    On Sun, 2009-06-21 at 19:50 +0530, Gurunandan R. Bhat wrote:
    I am sure that someone will write a regex for you that will work.
    However, why not use Mail::Log::Parse::Postfix (this is a Postfix log
    right?) and getting the parameters you want is as easy as
    $logline->{to} .. well almost :)
    Because it is overkill and will probably save me only a few lines of
    code for what I am doing.
    Regards
    Gurunandan




    On Sun, 2009-06-21 at 14:54 +0100, EASY buzzhost.co.uk wrote:

    OK, I'm an idiot. I just cannot get a simple regex match to work as
    intended. I've google, I dug out my books of regex and Perl but I hang
    my head in shame and ask here for help;

    Take This line;

    Jun 14 08:14:41 pingpong postfix/smtpd[22386]: NOQUEUE: reject: RCPT
    from host120-109-dynamic.56-82-r.retail.telecomitalia.it[82.56.109.120]:
    554 5.7.1 <[email protected]>: Sender address rejected: spoofing of
    domain; from=<[email protected]> to=<[email protected]> proto=SMTP
    helo=<82.56.109.120>

    I'm trying to grab the email address in the 'from=<...' portion. I can
    pin this down with look ahead look behind;

    (?(?=>)

    But it has a side effect of going to the last > on the line, not the
    closing half of the pair <>.

    To knock out the complications I drop to a simple pattern without the
    look ahead/behind;

    <.+\@.+>

    again it matches all the way to the end of the line, not just the
    opening < and closing > as intended.


    Now, a little research and I come up with 'greedy -v- non greedy'
    matching and thought I was on to something. But I can get that to play
    ball either;

    (.*?)>

    But No dice. After 8 hours on this I'm starting to kick myself blue. Can
    anyone put me out of my misery?


  • Chas. Owens at Jun 21, 2009 at 6:04 pm

    On Sun, Jun 21, 2009 at 11:58, EASY buzzhost.co.ukwrote:
    On Sun, 2009-06-21 at 19:50 +0530, Gurunandan R. Bhat wrote:
    I am sure that someone will write a regex for you that will work.
    However, why not use Mail::Log::Parse::Postfix (this is a Postfix log
    right?) and getting the parameters you want is as easy as
    $logline->{to} .. well almost :)
    Because it is overkill and will probably save me only a few lines of
    code for what I am doing.
    snip

    This statement shows me that you do understand what modules are for.
    They aren't there to save you lines of code. Modules are about giving
    to the community. Even if all you do is use the module you are giving
    back to the community. The more people who use a module, the more
    standard it becomes. Modules that are very standard make it easy to
    work on different code bases. Also, by using a module you may uncover
    an obscure bug. By reporting that bug, you start the process of
    fixing the problem, not only for yourself, but also for anyone else
    who uses the module.

    Everytime you decide to whip up your own version (without making it a
    module and putting it on CPAN), you are contributing to the
    [DarkPAN][1].

    [1]: http://www.perlfoundation.org/perl5/index.cgi?darkpan

    --
    Chas. Owens
    wonkden.net
    The most important skill a programmer can have is the ability to read.
  • EASY buzzhost.co.uk at Jun 22, 2009 at 3:02 am

    On Sun, 2009-06-21 at 14:03 -0400, Chas. Owens wrote:
    On Sun, Jun 21, 2009 at 11:58, EASY
    buzzhost.co.ukwrote:
    On Sun, 2009-06-21 at 19:50 +0530, Gurunandan R. Bhat wrote:
    I am sure that someone will write a regex for you that will work.
    However, why not use Mail::Log::Parse::Postfix (this is a Postfix log
    right?) and getting the parameters you want is as easy as
    $logline->{to} .. well almost :)
    Because it is overkill and will probably save me only a few lines of
    code for what I am doing.
    snip

    This statement shows me that you do understand what modules are for.
    They aren't there to save you lines of code. Modules are about giving
    to the community. Even if all you do is use the module you are giving
    back to the community. The more people who use a module, the more
    standard it becomes. Modules that are very standard make it easy to
    work on different code bases. Also, by using a module you may uncover
    an obscure bug. By reporting that bug, you start the process of
    fixing the problem, not only for yourself, but also for anyone else
    who uses the module.

    Everytime you decide to whip up your own version (without making it a
    module and putting it on CPAN), you are contributing to the
    [DarkPAN][1].

    [1]: http://www.perlfoundation.org/perl5/index.cgi?darkpan

    --
    Chas. Owens
    wonkden.net
    The most important skill a programmer can have is the ability to read.
    I'm looking for where I asked for your opinion? I don't see it
    anywhere :-) I'm not interested in the anal politics so please GET OUT
    MORE OFTEN.
  • Dr.Ruud at Jun 22, 2009 at 6:32 pm

    EASY buzzhost.co.uk wrote:

    I'm looking for where I asked for your opinion? I don't see it
    anywhere :-) I'm not interested in the anal politics so please GET OUT
    MORE OFTEN.
    *plonk*

    --
    Ruud

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupbeginners @
categoriesperl
postedJun 21, '09 at 1:54p
activeJun 22, '09 at 6:32p
posts9
users6
websiteperl.org

People

Translate

site design / logo © 2023 Grokbase