Regex for extracting filename from path

前端 未结 17 692
时光取名叫无心
时光取名叫无心 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:48

    also one more for file in dir and root

       ^(.*\\)?(.*)(\..*)$
    

    for file in dir

    Full match  0-17    `\path\to\file.ext`
    Group 1.    0-9 `\path\to\`
    Group 2.    9-13    `file`
    Group 3.    13-17   `.ext`
    

    for file in root

    Full match  0-8 `file.ext`
    Group 2.    0-4 `file`
    Group 3.    4-8 `.ext`
    

提交回复
热议问题