I'd like to remove character between {
and }
.
Example :
input_string = "i like apple {nobody knows}";
expected result :
"i like aple"
I'd like to remove character between {
and }
.
Example :
input_string = "i like apple {nobody knows}";
expected result :
"i like aple"
Share
Improve this question
edited Feb 1, 2013 at 14:26
Denys Séguret
382k90 gold badges810 silver badges775 bronze badges
asked Feb 1, 2013 at 14:22
guurnitaguurnita
4575 gold badges11 silver badges22 bronze badges
1
- There is an exact question the other day... – nhahtdh Commented Feb 1, 2013 at 14:23
2 Answers
Reset to default 16You 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,'')
let regex = /<([^>]+)>/g;
let match;
let result = {}
while ((match = regex.exec(content))){
if(match && match[0] && match[1])
result[match[0]] = match[1];
}
if(result && Object.keys(result).length){
Object.entries(result).forEach(([key, value]) => {
if(content.includes(key)){
content = content.replace(key, value);
}
})
}