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:
- regex#mp4
- [email protected]
- regex jiff
See Also:
- Regex To Check If Are Allowed File Types
- Regular Expression To Match Valid Filename
- Regex To Check If Are Allowed File Types
- Regex To Extract Filename From A Path
- Regex To Extract Domain Name From URL
- Regex To Extract Filename & Domain Name From URL
- Windows File Path Regular Expression
- Linux File Path Regular Expression
- Regex To Match Everything Before The Last Dot