hunagyp has asked for the wisdom of the Perl Monks concerning the following question:
The example input PARAM ($line) for this is: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; }
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!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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: regex with /s modifier does not provide the expected result
by choroba (Cardinal) on Aug 31, 2016 at 14:10 UTC | |
by hunagyp (Initiate) on Aug 31, 2016 at 14:43 UTC | |
|
Re: regex with /s modifier does not provide the expected result
by coicles (Sexton) on Sep 01, 2016 at 02:27 UTC |