Regular expression to remove content inside specific brackets

I have brackets that contain data like this:

[vc_tag][/vc_tag]

If the tag can contain any of about 30 pieces of text.

I need some regex that will remove any brackets containing vc_

I have this, but it removes everything, not just vc_:

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

I also tried:

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

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

It is written in PHP, by the way.

+4
source share
1 answer

You can try the following:

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

All Articles