I'm hating myself for not being able to figure this one out. I've hit super search several times this morning, but was unable to locate anything on point.

I have the following example as an input file:

from 200.184.31.70/1713 to 168.49.127.83/80 on interface from 66.65.121.23/500 to 168.49.143.217/500 on interface from 208.40.56.131 to 168.49.123.100 on interface
What I'm trying to do is pull the IP addresses out, and if a port is specified, pull that as well. (The port is anything following the / in the IP address).

I've come up with the following regex.

$inLine =~ /([0-9]+\.[0-9]+\.[0-9]+\.[0-9]+(\/[0-9]+)?)[\w]*([0-9]+\.[ +0-9]+\.[0-9]+\.[0-9]+(\/[0-9]+)?)/

The problem seems to be where I am trying to specify the optional / and port. If anyone can point me in the right direction, I'd really appreciate it. I'm pretty sure I'm overlooking something simple.

Thanks!

If things get any worse, I'll have to ask you to stop helping me.


In reply to Regex for IP and Optional Port by shockme

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.