DD
DevDash

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

InputResult
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

Want API access + no ads? Pro coming soon.