in reply to String Matching

m/<=\s*(\S+)[^[]+\[([^\]]+)/

Here it is with nicer formatting and a basic explanation:

m/ <=\s* (\S+) # Capture the email address following <= [^[]+\[ # Skip to the first subsequent square bracket. ([^\]]+) # Capture until a closing bracket. /x

You can tinker with it yourself here.

The email address will be in $1 and the IP will be in $2, following a successful match.

Update: Silly me for trusting the OP's spec. Kenosis mentioned to me that the exim record could, in addition to <= also contain any of ==, **, =>, *>, ->, and possibly some others. So the <= anchor is probably not ideal, but could be improved upon with (?:<=|==|\*\*|=>|\*>|=>) (plus whatever others are legal).


Dave

Replies are listed 'Best First'.
Re^2: String Matching
by stevbutt (Novice) on Aug 14, 2012 at 08:12 UTC

    Thanks Dave,

    The Spec is correct - This is already in a if/ifelse statement where we know if we are dealing with == ** etc So what you have shown me is just perfect,

    many thanks

    Steve

      Fantastic! My faith in humanity is restored. ;) ...and I'm glad it worked for you.


      Dave

        Sorry Dave, Spoke too soon

        My test box is Linux and it works fine there but the target system is Solaris and only has Perl 5.8.4

        I get errors there as follows

        Unrecognized escape \S passed through at ./syslog_smtp.pl line 36. Unrecognized escape \s passed through at ./syslog_smtp.pl line 36. Unrecognized escape \s passed through at ./syslog_smtp.pl line 36.

        Line 36 reads

        my ( $from, $srvrip ) = $remainder =~ m/<=\s*(\S+)[^[]+\[([^\]]+);