2

私はツイートの非常に大きなデータベースを持っています。ほとんどのツイートには、複数の #hashtags と @mentions があります。すべての #hashtags を 1 つの列にスペースで区切り、すべての @mentions を別の列に配置したいと考えています。#hashtagaと aの最初の出現を抽出する方法は既に知ってい@mentionます。しかし、私はそれらをすべて取得することを知りませんか?一部のツイートには、#ハッシュタグが 8 つも付けられています。手動でツイートを確認し、#ハッシュタグと @メンションをコピーして貼り付けるのは、5,000 件を超えるツイートでは不可能な作業のようです。

これが私が欲しいものの例です。列 A があり、列 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
4

2 に答える 2

1

正規表現の使用を検討してください。

Microsoft VBScript Regular Expressions 5.5fromへの参照を追加することで、VBA 内で正規表現を使用できます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に次の式を入力します (ハッシュタグ用):

=JoinMatches(A1,"#")

C1に次の式を入力します。

=JoinMatches(A1,"@")

これで、数式だけを下までコピーできます。

于 2012-11-30T08:01:16.733 に答える
0

他の文字 @ を使用してテキストを列に変換し、次に #s を使用して、残りのテキストを列 A に連結して戻すことができます。正規表現に慣れていない場合は、(@Zev-Spitz) を参照してください。

于 2012-11-30T08:19:06.833 に答える