I tried the following regular expression in script to extract lines not begining with capital letters and not ending with numbers.
-
if ($str =~/^[^A-Z].+[^0-9]$/) ## similarly /^[^A-Z].+\D$/
-
{
-
######
-
}
-
This didn't work. The pattern condition was applied only to begining of string. The lines returned contained both digits & non-digits at the end.
However, I could achieve the task as follows:
-
if (($str !~ /^[A-Z]/)&&($str !~ /[0-9]$/))
-
{
-
######
-
}
-
But, I need to know why the previous expression didn't work. I understand the problem with using negative grammar for pattern matching. But, I am unable to find any conceptual/ logical error in the first expression.
To boil down the above query,
-
if(/^[^A-Z]/)
-
{ print $_; }
-
will successfully return lines not begining with capital letters, while
-
if(/[^0-9]$/)
-
{ print $_; }
-
fails to return lines not ending with digits.It returns all lines.
Any help would be greatly appreciated.