A negative look ahead assertion ((?!...) - line 3 of the regex below) does the tricky bit:
use warnings; use strict; while (<DATA>) { chomp; if (! m{ /(\d+) # Get first bunch of digits follow +ing a / .*? Date\sTime\s # match date time string ( (?: (?! \s\d+/). )+ ) # Everything up to the space befor +e \d+/ [^/]+ / # Throw away the unwanted digits p +receeding / (\d+) # Grab last number (.*) # Grab tail for subsequent checkin +g }x # allow most white space and comme +nts ) { print "No match: $_\n"; next; } my ($first, $datetime, $last, $tail) = ($1, $2, $3, $4); if ($tail =~ /(\) | \.sta \)?) $/x) { print "Skipping $_\n"; next; } print "Extracted $first, $datetime, $last\n"; } __DATA__ 12345645/883700892.log Date Time 4 kkdjkdkd 889298383/883729083.dat 12345645/883700892.log Date Time 4 kkdjkdkd 889298383/883729083.sta (12345645/883700892.log Date Time 4 kkdjkdkd 889298383/883729083.dat) (12345645/883700892.log Date Time 4 kkdjkdkd 889298383/883729083.sta) Completely badly formed
Prints:
Extracted 883700892, 4 kkdjkdkd, 883729083 Skipping 12345645/883700892.log Date Time 4 kkdjkdkd 889298383/8837290 +83.sta Skipping (12345645/883700892.log Date Time 4 kkdjkdkd 889298383/883729 +083.dat) Skipping (12345645/883700892.log Date Time 4 kkdjkdkd 889298383/883729 +083.sta) No match: Completely badly formed
In reply to Re: splitting up a string based on character locations
by GrandFather
in thread splitting up a string based on character locations
by batcater98
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |