How to replace “{* foo *}” with nothing?

I want to replace all text what start with "{" and end with "}" including those "{" and "}". Text between them may be anything. =( I guess I need to use regex's there.

Let's imagine that $this->output is string that I want to replace. So I got this far... It don't work by the way. =(

$this->output = preg_replace( '/{*(.*)*}/', $this->output, $this->output );

Answers


You need to escape the *:

'/{\*(.*)\*}/'

Otherwise * is interpreted as quantifier. Furthermore, to have .* not to match as much as possible, make the * quantifier reluctant:

'/{\*(.*?)\*}/'

Need Your Help

How to run a javaweb project through Main function in Netbeans´╝č

java-ee netbeans main

I've created a JavaWeb Project in Netbeans7.2 following the book Beginning JavaEE6 Platform with GlassFish3 2nd edition. The book uses Maven and commandline to compile and package while I'm using

Can I submit form info to Google Spreadsheets with jQuery's AJAX?

jquery ajax google-docs google-spreadsheet

I like being able to use google spreadsheets, but it's tricky to integrate into my site visually. So I was thinking that I would recreate their form (an easy cut/paste), submit the form via AJAX, ...