Community Patterns

Community Library Entry

1

Regular Expression
Created·2016-02-18 19:01
Flavor·PCRE (Legacy)

/
(<p[^>]*>)(.*?)(<\/p>)|(<p[^>]*>)
/
ig
Open regex in editor

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