从string中删除推特正则expression式

我有一张填充了推文的Excel表格。 有几个条目包含@blahtypes的string等。 我需要保留文本的其余部分,并删除@blah部分。 例如:“@ villos hey dude”需要转化为:“hey dude”。 这是我到目前为止所做的。

Sub Macro1() ' ' Macro1 Macro ' Dim counter As Integer Dim strIN As String Dim newstring As String For counter = 1 To 46 Cells(counter, "E").Select ActiveCell.FormulaR1C1 = strIN StripChars (strIN) newstring = StripChars(strIN) ActiveCell.FormulaR1C1 = StripChars(strIN) Next counter End Sub Function StripChars(strIN As String) As String Dim objRegex As Object Set objRegex = CreateObject("vbscript.regexp") With objRegex .Pattern = "^@?(\w){1,15}$" .ignorecase = True StripChars = .Replace(strIN, vbNullString) End With End Function 

另外还有这样一个条目:shift‡Ÿãã|,,shift shift shift shift shift shift shift shift shift shift shift shift shift shift shift shift shift shift shift shift shift shift shift shift¹¹¹

我也需要他们了! 想法?

对于电子表格中的每一行,运行以下正则expression式: ^(@.+?)\s+?(.*)$

如果该行与正则expression式匹配,您将感兴趣的信息将在第二个捕获组中。 (通常零索引但位置0将包含整个匹配)。 如果你需要的话,第一个捕获组将包含twitter处理。

正则expression式在这里演示 。

但是,这不匹配不是回复的推文(以@开头)。 在这种情况下,区分常规推文和您不感兴趣的垃圾的唯一方法是将推文限制为字母数字 – 但这可能意味着如果某些推文包含任何非字母数字字符,则会漏掉某些推文。 下面的正则expression式将工作,如果这不是一个问题给你:
^(?:(@.+?)\s+?)?([\w\t ]+)$

演示2