题
不幸的是,我在regexp上很烂。如果我有这样的路:
/long/path/to/file
, ,我只需要extact file
.
如果有人供应 file/
我只需要 file
.
如果有人供应 /file/
, 我还需要 file
.
我一直在用 stringr
功能作为一个拐杖,但这似乎是直线上升 grep
领土。请帮忙?
解决方案
如果我理解正确,你可以使用 basename
函数。
f <- "/long/path/to/file"
basename(f)
# [1] "file"
其他提示
这个呢?
> path <- "/long/path/to/file"
> require(stringr)
> str_extract(path, "[^/]*$")
[1] "file"
不隶属于 StackOverflow