Python (re)

Image File Extension in PY

Match common image file extensions: jpg, jpeg, png, gif, webp, svg, avif, bmp, ico, tif, tiff.

Try it in the PY tester →

Pattern

regexPY
\.(jpe?g|png|gif|webp|svg|avif|bmp|ico|tiff?)$   (flags: i)

Python (re) code

pyPython
import re

pattern = re.compile(r"\.(jpe?g|png|gif|webp|svg|avif|bmp|ico|tiff?)$", re.IGNORECASE)
input_text = "photo.jpeg"
for m in pattern.finditer(input_text):
    print(m.group(0))

Stdlib `re` module — no third-party dependency. Works on Python 3.6+.

How the pattern works

\. matches the literal dot. The alternation group covers all common web and raster image extensions. jpe?g covers both jpg and jpeg. tiff? covers tif and tiff. The i flag makes matching case-insensitive so .PNG and .JPG also match.

Examples

Input

photo.jpeg

Matches

  • .jpeg

Input

logo.SVG

Matches

  • .SVG

Input

document.pdf

No match

Same pattern, other engines

← Back to Image File Extension overview (all engines)