问题
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