Skip to main content
Regexflux

File Extension

beginner

Extracts file extensions from filenames.

fileextensionparsingtype

Pattern

/\.(\w{1,10})$/gm

Try It

0 of 7 strings matched

Explanation

Matches a dot followed by 1-10 word characters at the end of a line. Captures the extension without the dot in group 1.

Test Strings

Matching

  • file.txt
  • image.png
  • archive.tar.gz
  • script.min.js

Non-matching

  • no-extension
  • README
  • file.

Language Compatibility

LanguageSupport
JSFull support
PYTHONFull support
JAVAFull support
PHPFull support
GOFull support

Code Snippets

const regex = /\.(\w{1,10})$/gm;
const text = "your text here";
const matches = text.match(regex);
console.log(matches);

Common Variations

Specific types

\.(?:jpg|jpeg|png|gif|svg|webp)$

Matches common image file extensions only

Related Patterns