FreeKB - Perl Trailing forward slash
Perl - 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.

/path/to/some

 



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 2dae9 in the box below so that we can be sure you are a human.




Comments

Web design by yours truely - me, myself, and I   |   jeremy.canfield@freekb.net   |