Regex for file extension

/\.([a-z0-9]{1,10})$/gim

Options
Matches

Examples

Note

Group 1 is the extension. For archive.tar.gz it is gz, the last one.

Matches in the example

  • ".pdf"
  • ".gz"
  • ".JPEG"

Token by token

  1. \. the character “.”
  2. ( a capturing group
  3. [a-z0-9]{1,10} one of: “a” to “z” or “0” to “9”, between 1 and 10 times, as many as possible
  4. ) end of group
  5. $ the end of the string (or line, with the m flag)

Other patterns