I have a path like this ../some/thing/foobar/foobar.happening and I want the character string between the last / and ..
I realize this will be easy for some, but I’m not yet familiar with regular expressions etc.
I also probably could do this by myself with strsplit, but I’m looking for an elegant one-liner, if possible.
Thanks in advance!
basenamewill give you the part after the last slash. Then, you can split on the dot (which you have to escape with two\)Then select the first element
I see you actually asked for a way other than
strsplit. Here’s a regular expression.*/[^/](inside the brackets,^means “not”), one or more times+.\\..*.Then it replaces that with only the stuff inside the parenthesis
[^/]+which is everything between the forward slash and the dot. The\\1means the stuff inside the first set of parenthesis. (there’s only one set in this case, but if there were a second we could refer to it with\\2)