Regular Expressions 101

Community Patterns

Community Library Entry

1

Regular Expression
PCRE (PHP <7.3)

/
(<p[^>]*>)(.*?)(<\/p>)|(<p[^>]*>)
/
ig

Description

Strip specific HTML tags from a string—opposite of PHP's strip_tags(). Replace letter 'p' with your tag name. Using PHP preg_replace(), example: preg_replace('/(<' . $tag . '[^>]>)(.?)(</' . $tag . '>)|(<' . $tag . '[^>]*>)/i', '$2', $string);

Submitted by Zachary Beschler - 9 years ago