Another trick you can use to do this job is to use a group (?>...) that disables backtracking. Disabling backtracking means that any expression using + or * will eagerly eat whatever it finds and will never come back to try something else if the template doesn't work. This means that all spaces before "Created" are eaten, so part of the regular expression (?!Created) always occurs in the exact right place.
if($string =~ /^(?>\*\s+(\w\w\w-\d\d-\d\d\d\d)\s+(\w+)\s+(\d+)\s+)(?!Created)/){ print "$1\n$2\n$3\n"; } else { print "no match\n"; }
It also has an added bonus to make your regular expression much faster.
This approach does not work for all problems, because many regular expressions must be able to indent to fit correctly. But that will work just fine for this.
user1919238
source share