regex remove nested tags

i want to remove a tag as well as the text w/in that tag.

for example:

[quote]blah blah i don't want any of this stuff[/quote] and this is the rest

so i use:

/\[quote\](.*?)\[\/quote]/

which works fine until you have a nested quote like so:

[quote]hello world [quote]foo bar[/quote] blah blah[/quote] and this is the rest

your assistance is greatly appreciated.

Thanks!

Bob
LVL 18
bobbit31Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

ozoCommented:
#!/usr/bin/perl
$_="[quote]hello world [quote]foo bar[/quote] blah blah[/quote] and this is the rest
[quote]blah blah i don't want any of this stuff[/quote] and this is the rest
"
;
($re=$_)=~s#((\[quote])|(\[/quote])|.)#${['(','']}[!$2]\Q$1\E${[')','']}[!$3]#gs;
$re=join"|",map{quotemeta}(eval{/$re/});
die $@ if $@;
s/$re//g;
print;
0
bobbit31Author Commented:
can you do that in ruby? please?
0
ozoCommented:
Can you guarantee that there will only be one set of nested quotes to remove?
Or that they will be nested no more than two deep?.
0
Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

bobbit31Author Commented:
i cannot :(
0
bobbit31Author Commented:
upping points
0
petiexCommented:
/\[quote\].*\[/quote\]/m

I tested that here: http://www.rubular.com/
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
bobbit31Author Commented:
thanks all!

giving ozo some points too as his solution also works
0
ozoCommented:
/\[quote\].*\[/quote\]/m
may not work properly without a guarantee that there will only be one set of quotes to remove
[quote]hello world [/quote]and this is the rest[quote] blah blah[/quote]
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Regular Expressions

From novice to tech pro — start learning today.