P
P
polyvoidex2018-06-10 18:10:17
PHP
polyvoidex, 2018-06-10 18:10:17

How to strip multiple nested data?

There is a string like:
[quote][quote][quote]a[/quote]b[/quote]c[/quote]
Which needs to be cast to the form:
[quote]c[/quote]
And [quote] can also be [ quote="user"].

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
dodo512, 2018-06-10
@polyvoidex

rextester.com/BCEL28233
Or so https://regex101.com/r/rufOQc/3

$re = <<<'END'
@
\G(?!\A)
(?: [^\[]+ | (?! \[/?quote). )*+ \K
(
    \[quote[^\]]*\]
    (?: [^\[]+ | (?!\[/?quote). | (?1) )*+ 
    \[/quote\]
)
| \[quote[^\]]*\] \K
@xi
END;

$str = preg_replace($re, '', $str);

S
Stalker_RED, 2018-06-10
@Stalker_RED

For example:
https://regex101.com/r/p2nAN3/1 And then find the last bracket ( strrpos
) from the middle part and cut it off, and everything in front of it.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question