[英]How to remove a word that starts with a certain character from a string in Javascript
我有一个像
'here is some #tweet from @someone to @somebody-else'
并且我需要删除所有以@mentions开头的单词(和短语),并返回不包含它们的字符串,以使其变为
'here is some #tweet from to'
如何在Javascript中做到这一点?
谢谢!
var str = 'here is some #tweet from @someone to @somebody-else';
str = str.replace(/\s?@\S+/g, '');
var s = 'here is some #tweet from @someone to @somebody-else';
s = s.replace(/\s?@[\w-]+/g, "");
//here is some #tweet from to
演示:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.