secondman
secondman

Reputation: 3277

Regex to Remove Content Inside Specific Brackets

I have brackets that contain data as so:

[vc_tag][/vc_tag]

Where tag could be any of about 30 pieces of text.

I need some regex that will remove any brackets that contain vc_

I have this, but it removes all instead of just vc_:

$data = preg_replace('/\\[(?>[^\\]]*)\\]/', '', $content);

I also tried:

$data = preg_replace('/\\[(vc_[^\\]]*)\\]/', '', $content);

which removes the opening [vc_tag] but not the closing [/vc_tag]

This is written in PHP by the way.

Upvotes: 4

Views: 492

Answers (1)

Casimir et Hippolyte
Casimir et Hippolyte

Reputation: 89547

You can try this:

$data = preg_replace('~\[/?vc_[^]]*]~', '', $content);

Upvotes: 4

Related Questions