in reply to RE: Getting an IP out of a string
in thread Getting an IP out of a string

Problem is it's not always going to be http://ipaddress in front - IE it's not always a link :-)

Sometimes it will be surrounded by formatting tags, other times by link tags.. basically looking through an HTML file for any IP address. Can do that no problem using hints from node mentioned above, but that returns the whole line - now need to strip anything but the IP :-)

Sorry if I wasn't clearer to start out with, starting to play with HTML::Parser now..

Replies are listed 'Best First'.
RE: RE: RE: Getting an IP out of a string
by knight (Friar) on Aug 17, 2000 at 00:15 UTC
    The problem is that what is or is not an IP address really depends on the file semantics, not just on what an IP address "looks like." A simple regex match for dotted-quad "IP addresses" in arbitrary text will give you false positives.

    In the HTML source for one site I maintain, for example, such a regex would match the following:
    1.41.1.1
    Is it an IP address? Nope, it's an RCS version number, and blindly assuming it's an IP address would be wrong at best and dangerous at worst.

    That said,
    @ip_addrs = m/{regex to match IP}/g;
    will select only the "IP address" texts from $_ for whatever regex you choose, without the danger of relying on $1.
      Thank you, that is exactly what I needed.

      And, yes, I prompt the user of the script to ensure the strings it has chosen from an html file are indeed ones that currently contain IP addresses, and are ones they would like updated in the future :-)
      ie: I'm not relying on my shoddy coding alone.