Regular Expressions 101

Community Patterns

Get src and srcset image attributes, and other attributes

1

Regular Expression
PCRE (PHP <7.3)

/
<img(([^>]*)srcset\=(?:\"|\')([^\"\']*)(?:\"|\'))?([^>]*)src=(?:\"|\')([^\"\']*)(?:\"|\')(([^>]*)srcset\=(?:\"|\')([^\"\']*)(?:\"|\'))?([^>]+)*>
/
g

Description

Not depending on the src or srcset order, but some matches can be empty, depending on the img syntax.

Submitted by Geoffrey Crofte & Sébastien Decamme - 8 years ago