@robot ping'; I need to delete this part of the line

JS regex replace idle

I have a js string

var str = '<at id="11:12345678">@robot</at> ping'; 

I need to delete this part of the line

<at id="11:12345678">@

So I'm trying to use

var str = str.replace("<at.+@","");

But after the exile there are no changes. Moreover, if I try to use match , it gives me

str.match("<at.+@");
//Result from Chrome console Repl
["<at id="11:12345678">@", index: 0, input: "<at id="11:12345678">@robot</at> ping"]

So the template is valid, but replace do nothing

+4
source share
1 answer

Use //for regex. Replace "<at.+@"with /<at.+@/.

var str = '<at id="11:12345678">@robot</at> ping'; 

str = str.replace(/<at.+@/,"");

console.log(str);
Run code

Documentation for replace

+4
source

Source: https://habr.com/ru/post/1672457/


All Articles