Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我想删除 and 之间的{字符}。
{
}
例子 :
input_string = "i like apple {nobody knows}";
预期结果 :
"i like aple"
您可以使用
var out = input_string.replace(/{[^}]*}/,'')
如果要删除多个匹配项,请使用
var out = input_string.replace(/{[^}]*}/g,'')
要删除 and 之间的东西/*,*/这个应该可以工作:
/*
*/
var out = input_string.replace(/(?!<\")\/\*[^\*]+\*\/(?!\")/g,'')