Community Patterns

Community Library Entry

2

Regular Expression
Created·2021-08-27 09:22
Flavor·PCRE2 (PHP)

/
(?=(<picture>))(\w|\W)*(?<=<\/picture>)
/
gm
Open regex in editor

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