2012-11-30 62 views
2

我有一個非常大的推文數據庫。大多數推文都有多個#hashtags和@mentions。我希望所有#hashtag都用一列中的空格和另一列中的所有@mentions分隔開。我已經知道如何提取第一個出現的#hashtag@mention。但我不知道要把它們全部拿出來?有些推文有8個#標籤。手動瀏覽推文並複製/粘貼#hashtags和@版本似乎是超過5000條推文的不可或缺的任務。將A列中的所有@mentions和#hashtags複製到Excel中的B列和C列中

這是我想要的一個例子。我有一個欄,我想這將填充列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 
+0

你付多少錢:)?說真的,如果你能描述你所嘗試的和你的編程技能水平,那麼這將有所幫助:創建宏,使用VBA,使用Excel對象模型和正則表達式。從常見問題解答:**您的問題應合理範圍。如果你可以想象整本書能夠回答你的問題,那麼你的要求太高了。另請參閱[這裏](http://stackoverflow.com/questions/how-to-ask)。 –

回答

1

請考慮使用正則表達式。

您可以在VBA中使用正則表達式,從Tools -> References開始添加對Microsoft VBScript Regular Expressions 5.5的引用。

Here是一個很好的起點,有很多有用的鏈接。


更新

增加了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把下面的公式(對於主題標籤) :

=JoinMatches(A1,"#") 

C1柱把下面的formu la:

=JoinMatches(A1,"@") 

現在你可以只複製公式一路下來。

+0

這是一個比答案更多的評論。 – brettdj

0

您可以使用其他字符@將文本轉換爲列,然後反對#s,然後將其餘文本連接到列A,如果您不熟悉正則表達式,請參閱(@Zev-Spitz)

相關問題