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.

/path/to/some

 




Did you find this article helpful?

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



Comments


Add a Comment


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