我有这个输入字符串
~{RegExr1234124124.} was ~{created by gskinner.com}, and is ~{proudly hosted} by Media Temple.
并想要此输出:
was, and is by Media Template
我使用了/~{.*}+/g
正则表达式模式,但这是错误的
答案 0 :(得分:2)
.*
原因匹配字符串中{
之后的所有字符。
使用/~{[^}]+}/
匹配~{}
中的每个字符串,并使用.replace()
var newStr = str.replace(/~{[^}]+}/g, '');
var str = "~{RegExr1234124124.} was ~{created by gskinner.com}, and is ~{proudly hosted} by Media Temple.";
console.log(str.replace(/~{[^}]+}/g, '').trim());