Regular Expressions 101

Community Patterns

Match text in square brackets

3

Regular Expression
PCRE (PHP <7.3)

/
\[([^\[\]]++|(?R))*+\]
/

Description

Drupal7 Media Element in node body - A regex to match the media module square bracketted token/element for embedde images in node body. Use case - using the body text trimmed in a meta description - need to remove the media element as well as strip tags.

Submitted by iAugur - 8 years ago