将列A中的所有@mentions和#hashtags复制到Excel中的列B和C.
我有一个非常大的tweets数据库。 大多数推文都有多个#hashtags和@mentions。 我希望所有的#hashtags用一列中的空格和另一列中的所有@mentions分隔。 我已经知道如何提取@mention
和@mention
的第一次出现。 但是我不知道把它们全部弄清楚吗? 一些推特有多达8#的标签。 手动浏览推文并复制/粘贴#hashtags和@参数似乎是超过5000条推文的不可或缺的任务。
这是我想要的一个例子。 我有列A,我想要一个macros将填充列B和C.(我在Windows&Excel 2010)
Column A ----------- Dear #DavidStern, @spurs put a quality team on the floor and should have beat the @heat. Leave #Pop alone. #Spurs a classy organization. Live broadcast from @Nacho_xtreme: "Papelucho Radio"http://mixlr.com nachoxtreme-radio … #mixlr #pop #dance "Since You Left" by @EmilNow now playing on KGUP 106.5FM. Listen now on http://www.kgup1065.com #Pop #Rock Family Night #battleofthegenerations Dad has the #Monkeys Mom has #DonnieOsman @michaelbuble for me #Dubstep for the boys#Pop for sissy @McKinzeepowell @m0ore21 I love that the PNW and the Midwest are on the same page!! #Pop
我想要列B看起来像这样:
Column B -------- #DavidStern #Pop #Spurs #mixlr #pop #dance #Pop #Rock #battleofthegenerations #Monkeys #DonnieOsman #Dubstep #Pop #pop
而C列看起来像这样:
Column C: ---------- @spurs @heat @Nacho_xtreme @EmilNow @michaelbuble @McKinzeepowell @m0ore21
考虑使用正则expression式。
您可以在VBA中使用正则expression式,方法是从Tools -> References
添加对Microsoft VBScript Regular Expressions 5.5
Tools -> References
。
这里有一个很好的起点,有很多有用的链接。
更新
在添加对Regular Expressions
库的引用后,将以下函数放入VBA模块中:
Public Function JoinMatches(text As String, start As String) Dim re As New RegExp, matches As MatchCollection, match As match re.pattern = start & "\w*" re.Global = True Set matches = re.Execute(text) For Each match In matches JoinMatches = JoinMatches & " " & match.Value Next JoinMatches = Mid(JoinMatches, 2) End Function
然后,在单元格B1
input以下公式(对于标签):
=JoinMatches(A1,"#")
在C1
栏中input下面的公式:
=JoinMatches(A1,"@")
现在,您可以一直复制公式。
您可以使用其他字符@将文本转换为列,然后反对#s,然后将其余的文本连接在一起以备列A,如果您不熟悉正则expression式,请参阅(@Zev-Spitz)