В одну сторону (с ароматом perl
):
m|\A(.*/(?(?!.*\.gif$).*))|
Пояснение:
m| ... | # Regexp.
\A # Begin of line.
( # Group 1.
.*/ # All characters until last slash.
(? # Conditional expression.
(?!.*\.gif$) # If line doesn't end with '.gif', match...
.*) # ... until end of line.
)
Тестирование ...
Содержимое script.pl
:
use warnings;
use strict;
while ( <DATA> ) {
printf qq[%s\n], $1 if m|\A(.*/(?(?!.*\.gif$).*))|;
}
__DATA__
/dir-images/no1/top-left.gif
/test-1/test-2/test
Запустите его как:
perl script.pl
и следующий результат:
/dir-images/no1/
/test-1/test-2/test