Regular expression to remove a file's extension

后端 未结 9 2059
死守一世寂寞
死守一世寂寞 2020-11-30 01:09

I am in need of a regular expression that can remove the extension of a filename, returning only the name of the file.

Here are some examples of inputs and outputs:<

9条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-30 01:42

    another no-regex way of doing it (the "oposite" of @Rahul's version, not using pop() to remove)

    It doesn't require to refer to the variable twice, so it's easier to inline

    filename.split('.').slice(0,-1).join()
    

提交回复
热议问题