Regular Expressions 101

Community Patterns

extract most parts of possible <IMG> tag attributes (Oren Wassersprung)

0

Regular Expression
PCRE (PHP <7.3)

/
(<img[^>]src="([^"]+)"[^>]?(alt="(.*?)")?[^>]?(title="(.*?)")?(style="([^"]*)")?[^>]*>)
/
g

Description

this reg will extract:

  1. "content" of SRC
  2. "content" of ALT
  3. complete width="???"
  4. "content" of style attr.

do we really need anything else to format an image?

Submitted by anonymous - 6 years ago