我想从JavaScript中不带文件名的文件路径中获取目录。我希望输入和输出的行为如下。
Input: '/some/path/to/file.txt'
Output: '/some/path/to'
Input: '/some/path/to/file'
Output: '/some/path/to/file'
Input: '/some/folder.with/dot/path/to/file.txt'
Output: '/some/folder.with/dot/path/to'
Input: '/some/file.txt/path/to/file.txt'
Output: '/some/file.txt/path/to'
我正在考虑用RegExp
来做这件事。但是,不确定应该如何编写确切的RegExp。
有没有人能帮我找到比这个或者RegExp更有效的解决方案呢?
转载请注明出处:http://www.yojatech.com/article/20230526/1178055.html