Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove a certain starting symbol and its closing symbol, but not the contents?

Tags:

string

regex

php

Consider this string:

foo{This is my inner content. Hello}

What I want to do with regex is make it so it becomes like this:

This is my inner content. Hello

Note that I only want to match foo{ and }, when put together and used like that. I don't want, for example, foo2{ and }.

Is there a way?

like image 339
Lucas Avatar asked Nov 24 '25 02:11

Lucas


2 Answers

Use:

$str = preg_replace('/foo\{([^}]*)\}/', '$1', $str);
like image 66
xdazz Avatar answered Nov 25 '25 16:11

xdazz


Seems pretty simple:

/foo{(.*?)}/
like image 35
Explosion Pills Avatar answered Nov 25 '25 17:11

Explosion Pills



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!