Regular Expression To Extract File Extension From String

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:

Regex Is Copied!