Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cut off extension of filename [duplicate]

I have a list of filenames like

index.min.html
index.dev.html
index.min.js
index.dev.js
There.are.also.files.with.multiple.dots.and.other.extension

I want to cut off the extensions of the filenames, but the problem is that I can only use match for this task.

I tried many regular expressions looking like "index.min.html".match( /^((?!:(\.[^\.]+$)).+)/gi ); to select the filename without the last dot and extension, but they selected either the hole filename, nothing or the part before the first dot. Is there a way to select only the filename without extension?

like image 643
Cubi73 Avatar asked Dec 01 '22 16:12

Cubi73


1 Answers

Why regex? Simple substring expressions make this a lot simpler:

var filename = 'index.something.js.html';

alert(filename.substr(0, filename.lastIndexOf(".")));
like image 82
Paddy Avatar answered Dec 10 '22 11:12

Paddy