Anyone be able to help me with this regex please? I need an expression that will match the line that does not contain the “Created” string at the end. This script is being used to read the headings on some source code.
$string = "* JAN-01-2001 bugsbunny 1234 Created Module";
#$string = "* DEC-12-2012 bugsbunny 5678 Modified Module";
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$4\n";
} else {
print "no match\n";
}
When using the first $string definition, I need the match to fail because it has the word “Created” at the end of it. When using the second $string definition, it should pass and I need to pull out the date($1), user($2), change number($3) and description($4).
The expression above is not working. Any advice please?
Close:
You need to allow any number of non-newline characters before
Created, therefore the.*.Otherwise, the regex would simply back up by one character when matching
\s+, so the following text would be" Created", and then(?!Created)would match.See it here; notice how the match stops one space before
Created.