Regex for Image File Extension
Regex Pattern
\.(jpg|jpeg|png|gif|bmp|webp|svg|avif|heic)$Common image file extensions
Quick Answer
The regex pattern for image file extension is `\.(jpg|jpeg|png|gif|bmp|webp|svg|avif|heic)$`. Common image file extensions. This works in JavaScript, Python, Ruby, PHP, Java, and most regex engines that support PCRE syntax.
Test Examples
| Input | Result |
|---|---|
| photo.jpg | ✓ Matches |
| icon.svg | ✓ Matches |
| avatar.webp | ✓ Matches |
| pic.HEIC | ✓ Matches |
| document.pdf | ✗ No match |
| file.txt | ✗ No match |
| image | ✗ No match |
Code Examples
javascript
const regex = /\.(jpg|jpeg|png|gif|bmp|webp|svg|avif|heic)$/; const isValid = regex.test(value);
python
import re
pattern = r'\.(jpg|jpeg|png|gif|bmp|webp|svg|avif|heic)$'
if re.match(pattern, value):
print("valid")ruby
pattern = /\.(jpg|jpeg|png|gif|bmp|webp|svg|avif|heic)$/ if value =~ pattern puts "valid" end
php
if (preg_match('/\.(jpg|jpeg|png|gif|bmp|webp|svg|avif|heic)$/', $value)) {
echo "valid";
}java
String pattern = "\\.(jpg|jpeg|png|gif|bmp|webp|svg|avif|heic)$"; boolean isValid = value.matches(pattern);
Frequently Asked Questions
Related Regex Patterns
File Extension
File extension at the end of a filename
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