Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Javascript regex to remove string inside bracket

I'd like to remove character between { and }.

Example :

 input_string = "i like apple {nobody knows}";

expected result :

"i like aple"
like image 736
guurnita Avatar asked Feb 01 '13 14:02

guurnita


1 Answers

You can use

 var out = input_string.replace(/{[^}]*}/,'')

If you want to remove more than one occurrence, use

 var out = input_string.replace(/{[^}]*}/g,'')

To remove things between /* and */ , this one should work :

 var out = input_string.replace(/(?!<\")\/\*[^\*]+\*\/(?!\")/g,'')
like image 87
Denys Séguret Avatar answered Sep 26 '22 20:09

Denys Séguret