Regex question (I believe)

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Regex question (I believe)

Post by Luke »

Say I wanted to find something like {this} in a file and replace it with whatever I wanted... would this be something I would do with regex or would there be an simpler solution?

If it's a regex thing, can somebody help me out with that? I have tried to understand regex for about 3 years, and it just ends up making me mad.
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Post by RobertGonzalez »

Totally regex. Unless you know what is inside the {}, then you could use a str_replace(). But most times these things are used in templating systems and utilize some form of regex. As to what form, well, let's say I studied arrays more than regex. Sorry.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Without a lexical definition for the content of the braces:

Code: Select all

#\{.+?\}#s
is pretty much the most open one you can get.
Post Reply