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

Updated:   |  Perl (Scripting) articles

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.



Did you find this article helpful?

If so, consider buying me a coffee over at Buy Me A Coffee


Add a Comment

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