Regular Expression help, please

S

Stan Brown

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?
 
B

Brian Wakem

Stan said:
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?


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
 
P

Paul Lalli

Stan said:
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.

"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.
Cab some kind guru enlighten me on this mystery?

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
 

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. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top