Regex for extracting filename from path

前端 未结 17 698
时光取名叫无心
时光取名叫无心 2020-12-03 01:02

I need to extract just the filename (no file extension) from the following path....

\\\\my-local-server\\path\\to\\this_file may_contain-any&character.pdf<

17条回答
  •  我在风中等你
    2020-12-03 01:34

    This will get the filename but will also get the dot. You might want to truncate the last digit from it in your code.

    [\w-]+\.
    

    Update

    @Geoman if you have spaces in file name then use the modified pattern below

    [ \w-]+\.      (space added in brackets)
    

    Demo

提交回复
热议问题