BytePane

Image Tag (src) Regex Pattern

Extracts image source URLs from HTML img tags. Useful for web scraping, SEO image audits, and content migration.

🌐
Web & HTML
Intermediate
Difficulty
HTML
Language
gi
Flags
// Regular Expression
/<img[^>]+src=["']([^"']+)["']/gi

Live Regex Tester

Pattern Breakdown

<img[^>]+src=["']([^"']+)["']
Character class [ ]
Group ( )
Quantifier { }
Anchor ^ $
Repetition * + ?
Escape \
Alternation |
Any char .

Code Examples

JavaScript

const regex = /<img[^>]+src=["']([^"']+)["']/gi;
const test = "<img src="photo.jpg" alt="Photo">";
console.log(regex.test(test)); // true

// Extract matches
const matches = test.match(regex);
console.log(matches);

Python

import re

pattern = r'<img[^>]+src=["']([^"']+)["']'
test = "<img src="photo.jpg" alt="Photo">"
match = re.findall(pattern, test, re.IGNORECASE)
print(match)  # Found!

Go

package main

import (
    "fmt"
    "regexp"
)

func main() {
    re := regexp.MustCompile(`<img[^>]+src=["']([^"']+)["']`)
    fmt.Println(re.MatchString("<img src="photo.jpg" alt="Photo">")) // true
}

Common Use Cases

Image extractionSEO auditingaccessibility checking

Match Examples

InputResult
<img src="photo.jpg" alt="Photo">Match
<div>no image</div>No Match

About the Image Tag (src) Regex

Extracts image source URLs from HTML img tags. Useful for web scraping, SEO image audits, and content migration.

Regular expressions (regex) are powerful pattern matching tools used across virtually all programming languages. The image tag (src) pattern is classified as intermediate difficulty in the web & html category. This pattern is specifically designed for HTML.

When using this regex, always consider edge cases and test thoroughly with real-world data. Use the interactive tester above to validate the pattern against your specific inputs before deploying to production.

Need More Regex Patterns?

Browse our complete library of 100+ regex patterns with interactive testers.

Frequently Asked Questions

What is the Image Tag (src) regex pattern?

Extracts image source URLs from HTML img tags. Useful for web scraping, SEO image audits, and content migration.

How do I use the Image Tag (src) regex?

Use the pattern /<img[^>]+src=["']([^"']+)["']/gi in your code. In JavaScript: new RegExp('<img[^>]+src=["\']([^"\']+)["\']', 'gi'). Test it above with your own input.

What does this Image Tag (src) regex match?

This pattern matches: "<img src="photo.jpg" alt="Photo">". It does NOT match: "<div>no image</div>". Image extraction, SEO auditing, accessibility checking.

Is the Image Tag (src) regex beginner-friendly?

This pattern is rated Intermediate. It uses some advanced features like character classes and quantifiers.

What languages support the Image Tag (src) regex?

This pattern works in HTML. Syntax may vary slightly between regex engines.

Can I modify the Image Tag (src) regex for my use case?

Yes! Use the interactive tester above to modify the pattern and test with your own data. Common modifications include making it case-insensitive (add 'i' flag), matching globally (add 'g' flag), or adjusting character classes.

Related Tools