assuming,
string1 = "/var/usr/local/noob/"
i need to start from the last character to the closest “/” preceiding it.
so i am expecting:
remove_last_block_of_string()
i should get
“/var/usr/local/noob”
if i run remove_last_block_of_string() again,
"/var/usr/local"
running it again,
"/var/usr"
You can use this:
as in,
but if you’re manipulating file paths, it would be better to use the Pathname library.