我有一个JS字符串
var str = '<at id="11:12345678">@robot</at> ping';
Run Code Online (Sandbox Code Playgroud)
我需要删除字符串的这一部分
<at id="11:12345678">@
Run Code Online (Sandbox Code Playgroud)
所以我想尝试使用
var str = str.replace("<at.+@","");
Run Code Online (Sandbox Code Playgroud)
但是在执行后没有变化.此外,如果我尝试使用匹配它给我
str.match("<at.+@");
//Result from Chrome console Repl
["<at id="11:12345678">@", index: 0, input: "<at id="11:12345678">@robot</at> ping"]
Run Code Online (Sandbox Code Playgroud)
因此,模式实际可行,但无需替换
使用//了regex.替换"<at.+@"为/<at.+@/.
var str = '<at id="11:12345678">@robot</at> ping';
str = str.replace(/<at.+@/,"");
console.log(str);Run Code Online (Sandbox Code Playgroud)
替换文档