[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: [MacPerl] REgular Expression for IP address



$_=3D3D"
   Mark wrote:
   Can anyone help me with a regular expression to pull out
   numeric IP addresses from a line of text (i.e 192.168.0.2)? I've
   tried /(\d+)\.(\d+)\.(\d+)\.(\d)/ but to no avail.
";

##  Hi Mark!
##  Just grant another set of round brackets
##          and one more   +   in your expression,
##          and let it run. Catch the IP address as $1.

/((\d+)\.(\d+)\.(\d+)\.(\d+))/;
print "\(1.) $1\n";
$IPN=3D3D$1;
$IPN =3D3D~ s/\./x/g;
@IPN =3D3D split "x", $IPN;
    ## Sorry for these two lines -- but how could I have split at "."??
    ## This does not work:  @IPN =3D3D split ".", $1;
    ##      nor does this:  @IPN =3D3D split "\.", $1;
print "(2.) ", join (" / ", @IPN), "\n";
for (0..3)  {
  print "(3.$_.) IPN part $_: $IPN[$_]\n"   }

##  Greatings from the Old World (for ever young)
##  Gr=3DFC=3DDFe aus der alten Welt (der ewig jungen)!
##
##  Detlef Lindenthal <detlef@lindenthal.com>







# =3D3D=3D3D=3D3D=3D3D=3D3D Want to unsubscribe from this list?
# =3D3D=3D3D=3D3D=3D3D=3D3D Send mail with body "unsubscribe" to macperl-re=
quest@macp=3D
erl.org