Hello, I am new to perl, I am stuck on regex part of parsing a file, help would be appreciated. I am parsing a log file which has log entries per line. I am loading regex match in a scalar.
I am trying to match this data:
some_fields msg="http_decoder: HTTP.Unknown.Tunnelling" some_fields
This message keeps on changing.
Here is my regex:
/msg=\"+((?:([^:,]+):\s|)([^,]+?)\s*(?:\s*,.*?|)))\"+/
Here is my script:
foreach $message (@logs) { if ($message =~ /msg=\"+((?:([^:,]+):\s|)([^,]+?)\s*(?:\s*,.*?|))\"+/) + { print $message"\n"; } }
I tried online regex tools and this matches the string but when using perl it does not show any result.
I also tried adding the global match /g still does not work. Any clue? I tried several combinations it does not work. If I use the regex:
if ($message =~ /^msg/) - It only gives me msg="http_decoder: as output
I want the entire string
msg="http_decoder: HTTP.Unknown.Tunnelling"
I also tried
(/^msg=\"(.*?)\"+) This also gives me msg="http_decoder:

In reply to Perl Regex by cipher

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.