Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Regular expression for everything between two characters

Tags:

regex

I'm trying to build a regular expression which allows me to remove tags in a string. These tags always look like this: {...}. I've tried \{.*\} so far but unfortunately this won't work if these tags occur two times. For Example: {123} Hello {asdas}. The entire line would be deleted since it starts with a { and end with a }. So, how can I avoid this behaviour?

Thanks in advance.

like image 619
Steffen Avatar asked May 20 '26 03:05

Steffen


1 Answers

\{[^}]*\}

would probably do it.

An opening bracket, followed by any number of anything besides a closing bracket, followed by a closing bracket.

like image 106
Phillip Schmidt Avatar answered May 22 '26 23:05

Phillip Schmidt