Regex for Extracting a File Extension
Matches the file extension at the end of a filename.
Published October 12, 2026
Matches the file extension at the end of a filename.
Key points
- The capture group (in parentheses) isolates just the extension without the leading dot
- Doesn't handle files with no extension or multiple dots perfectly — adjust based on your exact needs
Example
\.([a-zA-Z0-9]+)$