我想创建一个JavaScript函数来替换后跟@
的单词示例:
var sample = "Hello @Jon how are you";
var result = myfunction(sample);
// result should be like "Hello xxxxxx how are you"
此处@符号也需要更换。
答案 0 :(得分:2)
@\S+
试试这个。xxx
。见。演示。
https://regex101.com/r/sJ9gM7/38
var re = /@\S+/gm;
var str = 'Hello @Jon how are you';
var subst = 'x';
var result = str.replace(re, subst);
答案 1 :(得分:2)