FreeKB - Perl (Scripting) Trailing forward slash
Perl (Scripting) - Trailing forward slash

Let's say you have a string that contains multiple forward slashes, like this.

$foo = "/path/to/some/directory";


The following regular expression will remove everything after the last forward slash.

$foo =~ s|\/[^/]+$||;


Printing $foo . . .

print $foo;


. . . should return the following.



Add a Comment

We will never share your name or email with anyone. Enter your email if you would like to be notified when we respond to your comment.

Please enter 8cd2e in the box below so that we can be sure you are a human.


Web design by yours truely - me, myself, and I   |   |