Hi Monks, I've the following code snippet:
sub splitLine { my $line = shift; my $pattern = shift; # by default, it is "ERROR" my %header; # DD.MM.YYYY HH:MM:SEC USEC + ERROR/WARN [pool-def] class-name msg my $sPattern = '(\d{2}.\d{2}.\d{4}).*?(\d{2}:\d{2}:\d{2}).\d{0,3}. +*?\*(' . $pattern . ')\*.*?(\[.*?\]).(.*?\..*?\s+?)(.*)'; if ($line =~ /$sPattern/s) { my $ts = parseLogEntryTimeStamp($1, $2); %header = ( 'timestamp' => $ts, 'date' => $1, 'time' => $2, 'severity' => $3, 'thread' => $4, 'class' => $5, 'msg' => $6); print "$7 \n"; #doTrace %header; } return %header; }
The example input PARAM ($line) for this is:
30.08.2016 08:00:00.004 *ERROR* [pool-7-thread-5] com.day.cq.reporting +.impl.snapshots.SnapshotServiceImpl Error accessing repository during + creation of report snapshot data javax.jcr.LoginException: Cannot derive user name for bundle com.day.c +q.cq-reporting [313] and sub service null
My goal is: cut into meaningful pieces this example text. My regex above works almost fine, except the last capture group. In perl, the last capture group only gives back this: 'Error accessing repository during creation of report snapshot data' In an online tester (https://regex101.com/r/eB7cR3/1) with the /s modifier, the last capture group gives back everything until the last char. Does anyone have any idea, why perl does not do the same? (or can you suggest another approach on this regex? It might be quite "messy" :D) Thanks a lot in advance for any advice!

In reply to regex with /s modifier does not provide the expected result by hunagyp

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.