Here's a solution I sent to the group earlier...

For the array thing, have you considered using a hash instead?? How do you
know where to insert the data in the array? Is it needed after another
value, or at a certain element??

John

-----Original Message-----
From: John Edwards 
Sent: 14 June 2001 16:29
To: '[EMAIL PROTECTED]'; [EMAIL PROTECTED]
Subject: RE: regex matching




This will give you the IP only if valid. I've attached as a file too in case
the code gets mangled.

---
$string = "here is a sample with 123.456.123.456 in the middle.";

if ($string =~
/([01]?\d\d|2[0-4]\d|25[0-5])\.([01]?\d\d|2[0-4]\d|25[0-5])\.([01]?\d\d|2[0-
4]\d|25[0-5])\.([01]?\d\d|2[0-4]\d|25[0-5])/) {

        print "String <$string> contains a valid IP <$&>\n";
} else {
        print "String <$string> contains no valid IP\n";
}

$string2 = "here is a sample with 123.156.123.156 in the middle.";


if ($string2 =~
/([01]?\d\d|2[0-4]\d|25[0-5])\.([01]?\d\d|2[0-4]\d|25[0-5])\.([01]?\d\d|2[0-
4]\d|25[0-5])\.([01]?\d\d|2[0-4]\d|25[0-5])/) {
        print "String2 <$string2> contains a valid IP <$&>\n";
} else {
        print "String2 <$string2> contains no valid IP\n";
}
---

John

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]
Sent: 14 June 2001 16:12
To: [EMAIL PROTECTED]
Subject: regex matching


i have a basic knowledge of regex but i want to know if there is a
simpler way to pull patterns out of a line.

if i have a line like:

      here is a sample with 123.456.123.456 in the middle.

m/\d\.\d\.\d\.\d/ will match the entire line. is there an easy way to
get only the ip address?

thanks..

Brian T. Wallace
Engineer



--------------------------Confidentiality--------------------------.
This E-mail is confidential.  It should not be read, copied, disclosed or
used by any person other than the intended recipient.  Unauthorised use,
disclosure or copying by whatever medium is strictly prohibited and may be
unlawful.  If you have received this E-mail in error please contact the
sender immediately and delete the E-mail from your system.


 <<test.zip>>  

test.zip

Reply via email to