因此,我一直在使用node.js和Javscript使用node-webkit编写一个twitter客户端。

而且,最终我已经到了转推以文本形式传递的地步。

RT @somename: status


我尝试找到某种正则表达式来替换RT @someone:,但完全没有任何内容。但是我什么也找不到。

我不太擅长,也不了解正则表达式,因此不胜感激!

最佳答案

您可以使用以下内容。

var str = '@foo @bar @baz RT @somename: status',
    res = str.replace(/RT\s*@\S+/g, '');

console.log(res); // => "@foo @bar @baz  status"


正则表达式:

RT             'RT'
\s*            whitespace (\n, \r, \t, \f, and " ") (0 or more times)
 @             '@'
 \S+           non-whitespace (all but \n, \r, \t, \f, and " ") (1 or more times)


另一种选择是匹配直到包括冒号。

str.replace(/RT\s*@[^:]*:/g, '');

10-08 07:40
查看更多