This is a seperate question from my Matching An IP Address post, but it is related.

I am looking at data of the type:

136.1.1.154:33672 -> 64.210.209.51:80 -> 192.168.1.145:80 + tcp 65.201.211.176:14664 -> 64.210.209.54:80 -> 192.168.1.78:80 + tcp 67.38.95.86:2116 -> 64.210.209.50:80 -> 192.168.1.103:80 + tcp 198.49.222.246:52469 -> 64.210.209.54:80 -> 192.168.1.79:80 + tcp 193.80.106.152:3781 -> 64.210.209.61:80 -> 192.168.1.81:80 + tcp 67.28.79.24:3248 -> 64.210.209.54:80 -> 192.168.1.79:80 + tcp 128.187.192.39:1218 -> 64.210.209.54:80 -> 192.168.1.78:80 + tcp 128.187.192.39:1209 -> 64.210.209.51:80 -> 192.168.1.144:80 + tcp

The regex another user suggested was
my $re_ip = qr/(\d+\.\d+\.\d+\.\d+):\d+/; my $re_line = qr/ ^ \s* $re_ip \s* -> \s* $re_ip \s* -> \s* $re_ip /x;

However, I have found this does not work. It is the $re_line which is the culprit.

The following patterns DO work:
qr/^\s*$re_ip\s*->\s*$re_ip\s*->\s*$re_ip/ qr/^ \s* $re_ip\s*->\s*$re_ip\s*->\s*$re_ip/x qr/^\s*$re_ip\s*-> \s* $re_ip\s*-> \s* $re_ip/x qr/ ^ \s* $re_ip\s*->\s*$re_ip\s*->\s*$re_ip/x

The following do NOT work:
qr/ ^ \s* $re_ip \s*->\s*$re_ip\s*->\s*$re_ip/x qr/ ^ \s* $re_ip\s*->\s*$re_ip \s*->\s*$re_ip/x

Based on this, I think it is the space between a $re_ip and a \s* that is the culprit.

Can anyone explain why? I thought /x was supposed to allow whitespace within a regex.

Thanks.


<-> In general, we find that those who disparage a given operating system, language, or philosophy have never had to use it in pratice. <->

In reply to Matching IP address continued by ibanix

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.