zhoradk zhoradk - 6 months ago 19
PHP Question

Regular expression to find group of tags for PHP

Please help me to write regular expression to find group of tags

output

[et_pb_codeadmin_label="Code"] [tag] [/et_pb_code]


if it is inside some other tags like

input

[et_pb_row][et_pb_columntype="1_2"]

[et_pb_codeadmin_label="Code"] [tag] [/et_pb_code]

[/et_pb_column]
[/et_pb_row]


And only 3 thing same all the time

[et_pb_...can be any text here

[tag]

[/et_pb_...can be any text here

I have this

[et_pb_section fullwidth="on" specialty="off"]
[et_pb_fullwidth_code admin_label="Fullwidth Code"]
[tag]
[/et_pb_fullwidth_code]
[/et_pb_section]


I need to get only this

[et_pb_fullwidth_code admin_label="Fullwidth Code"][tag][/et_pb_fullwidth_code]

Answer

You can use something Like:

preg_match_all('%(\[et_pb_.*?\]){2}\s+(\[et_pb_.*?\] \[tag\] \[/et_pb_.*?\])\s+(\[/et_pb_.*?\])%i', $subject, $result, PREG_PATTERN_ORDER);
echo $result[1][0];

DEMO