Regular Expression help, please

Discussion in 'Perl Misc' started by Stan Brown, Sep 12, 2005.

  1. Stan Brown

    Stan Brown Guest

    I'm trying to parse some tcpdump output (converted to text) to put it into
    a database.

    The records of interest look like this:

    170.85.113.61.34203

    Which is, of course an IP address with the port number prepended. I can't
    seem to manage to come up with a regex that will match this. I tried
    something like:

    /(\d{1,5}\.?){5}/

    But it does not seem to work.

    Cab some kind guru enlighten me on this mystery?
     
    Stan Brown, Sep 12, 2005
    #1
    1. Advertisements

  2. Stan Brown

    Brian Wakem Guest


    Looks OK to me.


    #!/usr/bin/perl

    use strict;
    use warnings;

    my $str = "somestuffhere170.85.113.61.34203somestuffhere";

    if ($str =~ m/((\d{1,5}\.?){5})/) {
    print "$1\n";
    }
    else {
    print "No match!\n";
    }


    $ perl tmp49.pl
    170.85.113.61.34203
     
    Brian Wakem, Sep 12, 2005
    #2
    1. Advertisements

  3. Stan Brown

    Paul Lalli Guest

    "does not work" is the worst of all possible error descriptions. You
    need to tell us what didn't work, how it didn't work, what kind of
    error message you received, etc.
    perl -e'$_ = q{170.85.113.61.34203}; print "Yes!\n" if
    /(\d{1,5}\.?){5}/'
    Yes!

    The only "mystery" here is what you're actually asking.

    Please read the Posting Guidelines, and then post a short-but-complete
    script that demonstrates your problem.

    Paul Lalli
     
    Paul Lalli, Sep 12, 2005
    #3
    1. Advertisements

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments (here). After that, you can post your question and our members will help you out.