Regular Expression To Extract File Extension From String

Category: Strings

Trying to extract a file extension from a string is tricky. You could use wildcard characters, or you could use phrase searches, but that’s very time-consuming and less than intuitive. So why not try using a regular expression?

This is a short Regular Expression we found on the web that helps developers quickly extract and match a file extension from a string. Enjoy!

/\.[0-9a-z]+$/i

Matches:

  • regext.zip
  • regex.gif
  • regex.webp

Non-matches:

See Also:

Sending
User Review
0 (0 votes)

Expression Flags

Flags Description
i Ignore case sensitive.
g Allows global search.
m Allows multiline search.