Skip to content

Instantly share code, notes, and snippets.

@stewartduffy
Last active June 24, 2024 07:37
Show Gist options
  • Save stewartduffy/481f21ea4906e611d934 to your computer and use it in GitHub Desktop.
Save stewartduffy/481f21ea4906e611d934 to your computer and use it in GitHub Desktop.
Regex to remove file extension from JS string.
var filenameFull = "tm_icons.png";
//Regex to remove
var filenameText = filenameFull.replace(/\.[^/.]+$/, "");
@Stef16Robbe
Copy link

thanks!

@anhtuank7c
Copy link

I would prefer simpler way:

var fileNameFull = "temp.icon.png";
var fileNameWithoutExtension = fileNameFull.substring(0, fileNameFull.lastIndexOf("."));
// result: temp.icon

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment