Relative Content

Tag Archive for regexperl

Swap filenames backwards

The following one-line script is to rename files from e.g. Foo_Bar_Baz.txt to Baz_Bar_Foo.txt:

Perl Why is this lazy regex acting greedily?

my $file = ‘/a/b/c.xxx’; my $path = $file =~ s’/.*?$”r; print “$pathn”; $path = $file =~ s’/[^/]*$”r; print “$pathn”; The second substitution gives what I was expecting a/b but the first gives an empty string. Why is the .*? slurping up the whole string? regex perl