Skip to main content
Data & Formatting · In-Browser Regular Expression Lab

Image Extension Regex — Match PNG, JPG, WebP, SVG & AVIF

Matches filenames ending with common web image formats (png, jpg, jpeg, webp, svg, avif, gif).

Flags:
//i
Match Found
Load Sample:
Match Inspection & Details1 match
Match #1:.png

Test Samples Verification Matrix

Expected Valid Samples (Should Match)

avatar.png Pass
hero-banner.webp Pass
icon.SVG Pass
photo.JPEG Pass

Expected Invalid Samples (Must Reject)

document.pdf Rejected (Pass)
bundle.js Rejected (Pass)
style.css Rejected (Pass)
image.png.txt Rejected (Pass)
Code Implementation Generator
// JavaScript / TypeScript (ES6+)
const pattern = /\.(jpe?g|png|gif|webp|svg|avif|ico|bmp)$/i;
const text = "avatar.png";

const isMatch = pattern.test(text);
console.log("Is Match:", isMatch);

if (isMatch) {
  const matches = text.match(pattern);
  console.log("Matches:", matches);
}

Regular Expression Token Breakdown

Case-insensitive check for common image file extensions at string termination. Each component of the regular expression serves a distinct syntactical purpose as mapped below:

Token PatternName / ComponentFunction & Rule
\.PeriodLiteral dot before extension.
(jpe?g|png...)Extension groupAllowed image format extensions.
$End of StringEnsures extension is at the end of filename.

Frequently Asked Questions

How to match image URLs with query params?
Change `$` to `(?:\?.*)?$` to permit query strings.
Browse All 40 Patterns