简体   繁体   中英

Removing extension type from a filename

I want to remove extension of a file name. For example:

Demo.csv --> Demo
thermal.jpg --> thermal

I have used following regex but its not working.

/(.*)[^.]+$/

Kindly help, thanks in advance!

您可以尝试以下RegExp:

/.+\.([^.]+)$/
var str='thermal.jpg.png'; // double extension to test behavior

var name=str.substr(0,str.lastIndexOf('.'));  // -> thermal.jpg

    name=str.substr(0,str.indexOf('.'));      // -> thermal

Hey thanks to all folks for your help!!! but this is the RegEXP which I got which is working in my scenario

^(.*\.)[^.]+$

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM