我想标记包括哈希和现金标签在内的 Twitter 消息。标记化的正确示例如下所示:
"Bought $AAPL today,because of the new #iphone".match(...);
>>>> ['Bought', '$AAPL', 'today', 'because', 'of', 'the', 'new', '#iphone']
我为此任务尝试了几个正则表达式,即:
"Bought $AAPL today,because of the new #iphone".match(/\b([\w]+?)\b/g);
>>>> ['Bought', 'AAPL', 'today', 'because', 'of', 'the', 'new', 'iphone']
和
"Bought $AAPL today,because of the new #iphone".match(/\b([\$#\w]+?)\b/g);
>>>> ['Bought', 'AAPL', 'today', 'because', 'of', 'the', 'new', 'iphone']
和
"Bought $AAPL today,because of the new #iphone".match(/[\b^#\$]([\w]+?)\b/g);
>>>> ['$AAPL', '#iphone']
我可以使用哪个正则表达式来在令牌中包含前导的尖号或美元符号?