If I have a string that looks like my name is {your name here} and I am from {country}.
I am trying to use preg_replace to remove the {content}
so the string ends up as my name is and I am from .
But I can not work out the regex for the pattern.
Can someone please help me out?
my name is and I am from .
is simply a sample st开发者_开发知识库ring.
it could be something like the current date is {current date} in {suburb}
Perhaps something like:
/\{[^{}]*}/
Untested, but should get you started. First you match the {, then everything except }, and then the final }.
edit: fixed it, and now it's actually tested ;)
You can try:
\{.*?}
For your "toolbox": there are online regular expression checkers, such as this one. It provides a good testbed since it is completely separate from your code.
+1 Evert -- you solution looks good.
$str = 'my name is {your name here} and I am from {country}.';
echo preg_replace('/{.*?}/', '', $str),"\n";
output:
my name is and I am from .
精彩评论