Regex for File Extension
Regex Pattern
\.[a-zA-Z0-9]+$File extension at the end of a filename
Quick Answer
The regex pattern for file extension is `\.[a-zA-Z0-9]+$`. File extension at the end of a filename. This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.
Test Examples
| Input | Result |
|---|---|
| image.jpg | ✓ Matches |
| document.pdf | ✓ Matches |
| archive.tar.gz | ✓ Matches |
| filename | ✗ No match |
| no.dot at end | ✗ No match |
Code Examples
javascript
const regex = /\.[a-zA-Z0-9]+$/; const isValid = regex.test(value);
python
import re
pattern = r'\.[a-zA-Z0-9]+$'
if re.match(pattern, value):
print("valid")ruby
pattern = /\.[a-zA-Z0-9]+$/ if value =~ pattern puts "valid" end
php
if (preg_match('/\.[a-zA-Z0-9]+$/', $value)) {
echo "valid";
}java
String pattern = "\\.[a-zA-Z0-9]+$"; boolean isValid = value.matches(pattern);
Frequently Asked Questions
Related Regex Patterns
Image File Extension
Common image file extensions
Video File Extension
Common video file extensions
Absolute Unix Path
Absolute filesystem path starting with /
Email Address
Validates a standard email address format
Email (RFC 5322 Compliant)
RFC 5322 compliant email validation with label length limits
URL (HTTP/HTTPS)
Validates HTTP and HTTPS URLs