当前位置: 动力学知识库 > 问答 > 编程问答 >

regex - Regular expression to find group of tags for PHP

问题描述:

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

output

[et_pb_...] [tag] [/et_pb_...]

(dots any text) 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]

other input

[et_pb_section fullwidth="on" specialty="off"]

[et_pb_fullwidth_code admin_label="Fullwidth Code"]

[tag]

[/et_pb_fullwidth_code]

[/et_pb_section]

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]

UPDT

I got it to work

DEMO

网友答案:

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

分享给朋友:
您可能感兴趣的文章:
随机阅读: