in reply to Clarify this Regular Expression

The ^ at the very start of the regex indicated the beginning of the line, as opposed negation. Thus, the regex looks for a typical numercial IP address at the start of a line; if found, it splits the line on whitespace and returns the parts as an array. Mind you, this isn't perfect (an ip of 999.999.999.999 will match though not legit), but it will make sure that any line that starts with something that looks like an IP is treated differently from everything else.

-----------------------------------------------------
Dr. Michael K. Neylon - mneylon-pm@masemware.com || "You've left the lens cap of your mind on again, Pinky" - The Brain

Replies are listed 'Best First'.
Re: Re: Clarify this Regular Expression
by chumley (Sexton) on Aug 17, 2001 at 02:34 UTC

    Mastering Regular Expressions has a discussion of a regex to match IP addresses, without matching anything that's not an IP. So Masem is correct in saying that this is a crude match.

    However, I would point out that sometimes you can live with this. If you know that the file you're searching will never have something that looks like an IP address but isn't, then you can use a simpler regular expression. I have used m/^(10\.\d+\.\d+\.\d+)/ to pull IP addresses out of files, when I know that all the IP's on the LAN I'm concerned with start with 10, and none of the files I'm searching will have anything that could return a false match.

    Chumley

    Imagine a really clever .sig here.