JJB has asked for the wisdom of the Perl Monks concerning the following question:

I have problems with 2 different if statements that use metacharacters.
if (/(abuse\@.* )/) { $abuse_email = ${1}; }
The data line it's reading looks like this,
remarks: Please report all problems to abuse@xxxxx.xxx for probes +, port scans etc.
print($abuse_email) shows that it contains abuse@xxxxx.xxx for probes, port scans etc. The xxxxx.xxx can be any size, and any characters How do I change the if statement so I only get the abuse@xxxxx.xxx string? Problem 2.
If (/(Net-.??-.??-.??-0-1)/) { $net_block = ${1}; }
The data is (Net-xxx-xxx-xxx-0-1) Each xxx group will all ways by 1 to 3 digits long and different combinations every time. When matched I want $net_block just to hold Net-xxx-xxx-xxx-0-1 What is the correct syntax? Thanks

Replies are listed 'Best First'.
Re: Help with Metacharacters syntax
by Zaxo (Archbishop) on May 29, 2004 at 23:00 UTC

    With disclaimers about matching general email addresses, the first problem is solved when you realize you want the regex to stop matching on whitespace. You have .* there which matches all of anything. Try this,

    if (/(abuse\@\S*)/) { # ... }

    For the second problem, you want quantifiers,

    if (/(Net-\d{1,3)-\d{1,3)-\d{1,3)-0-1)/) { # ... }
    See perlre and perlretut, which you can view locally with perldoc.

    After Compline,
    Zaxo

      some of the email address are not surrounded by white space. <abuse#tel2.it> or abuse#tel2.it or \abuse#tel2.it\ I need to be able to capture email address that are either surrounded by space or enclosed with special characters but have the special characters dropped.