I want to split a string so that I always return everything BEFORE the LAST underscore HELLO_xxxxxxxx.lst # should return HELLO HELLO_GOODBYE_xxxxxxxx.ls # should return HELLO_GOODBYE I have tried with rsplit but cannot get it to work. Any help appreciated