繁体   English   中英

如何从Javascript中的字符串中删除以某个字符开头的单词

[英]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 

演示:

http://regex101.com/r/aV0hF2

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM