Regular Expressions 101

Community Patterns

Enclose <div> tag with <p> tag when inside <p> tag

0

Regular Expression
PCRE (PHP <7.3)

/
(?:<p>|\G)[^<>]*?\K(<div>.*?<\/div>)|<\/p>\K(?R)
/
g

Description

Change the <div> tags only when they are within a <p> tag.

Submitted by LukStorms - 8 years ago