Skip to main content
CalcHive

Regex for File Extension

Matches filenames and extracts the file extension. Captures extensions up to 10 characters long.

Pattern

/^.+\.([a-zA-Z0-9]{1,10})$/

Pattern Breakdown

TokenExplanation
^Start of string
.+One or more characters (filename)
\.Literal dot before extension
([a-zA-Z0-9]{1,10})Extension: 1-10 alphanumeric characters (captured)
$End of string

Test Examples

InputMatch?
document.pdfMatch
archive.tar.gzMatch
image.pngMatch
noextensionNo match
.hiddenNo match

Common Use Cases

  • File upload validation
  • File type filtering
  • Directory listing

Variations

\.(jpe?g|png|gif|svg|webp)$

Specific image extensions

\.(js|ts|jsx|tsx)$

JavaScript/TypeScript files

Want to test this pattern with your own data?

Open the Regex Tester