Regular Expressions 101

Community Patterns

Community Library Entry

2

Regular Expression
PCRE2 (PHP >=7.3)

/
(?=(<picture>))(\w|\W)*(?<=<\/picture>)
/
gm

Description

This regex will help you to parse html tag.

Example

<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <title>Title</title>
</head>
<body>
    <picture>
        <source srcset="mobile.png" ></source>
        <source srcset="tablet.png" ></source>
        <source srcset="desktop.png" ></source>
        <img srcset="default.png">
    </picture>
</body>
</html>

Output

<picture>
    <source srcset="mobile.png" ></source>
    <source srcset="tablet.png" ></source>
    <source srcset="desktop.png" ></source>
    <img srcset="default.png">
</picture>
Submitted by denchiklut - 3 years ago