Thread RE recursion (24 answers)
Opened by linuxCowboy at 2014-04-15 20:19

linuxCowboy
 2014-04-19 09:37
#174864 #174864
User since
2014-01-29
30 Artikel
BenutzerIn
[default_avatar]
Recursion:
s!<(\w+)[^>]*>([^<]*|(?R))*</\1>!!g;

entspricht:
s!<(\w+)[^>]*>[^<]*</\1>!!g while /<\w+[^>]*>/;

Code: (dl )
1
2
3
4
S='<div > <div > </div><div > not_show_1 </div> </div> show_1 <div > <a > not_show_2 <i /> </a> <s> </s> </div> show_2'

echo $S | perl -pe 's!<\w+\s*/>!!g; s!<(\w+)[^>]*>([^<]*|(?R))*</\1>!!g;'
show_1 show_2

Nur zuerst die self-closing tags entfernen und eine backreference verwenden!

:-)

We choose to go to the moon not because it is easy, but because it is hard!

View full thread RE recursion