Skip to content

Instantly share code, notes, and snippets.

@stewartduffy
Last active August 10, 2022 03:03
Show Gist options
  • Star 11 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • 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