Javascript regex to remove string inside bracket

荒凉一梦 提交于 2021-02-08 19:40:08

问题


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

Example :

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

expected result :

"i like aple"

回答1:


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,'')


来源:https://stackoverflow.com/questions/14648375/javascript-regex-to-remove-string-inside-bracket

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!