in reply to Regex to match an IP address that is embedded inside of another string

Take a look at Regular expression anchors. In particular \b.

Premature optimization is the root of all job security
  • Comment on Re: Regex to match an IP address that is embedded inside of another string

Replies are listed 'Best First'.
Re^2: Regex to match an IP address that is embedded inside of another string
by adamZ88 (Beadle) on Apr 19, 2016 at 22:13 UTC

    Thank you for your prompt response. The colon and other hex characters will always follow the last octet. I Tried your suggestion, and it still matches other ips that begin the same way on the fourth octet. Here is how I modified my code

    if ($linebuf =~ /\d+\.$oc1\.$oc2\.$oc3\.$oc4:*/

      As I stated in my above post, you need to get rid of the *.

        Thank you, that did it. I also had to add "^" at the beginning of my RegEx<\p>

Re^2: Regex to match an IP address that is embedded inside of another string
by adamZ88 (Beadle) on Apr 19, 2016 at 22:26 UTC

    Will do, Thank you.