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

MVVMLight: Ask information/confirmation in a command?

c# wpf command mvvm-light separation-of-concerns

I've created my first MVVMLight project, and I've a question:

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.