Google表格提取重复的URL参数字符串

时间:2018-07-02 09:18:19

标签: google-sheets

我想将“ c =; t =; s =“值提取到列中,并在Google表格中使用带逗号的分隔字符串。 这些值最多可以重复10次。 C =总是只有两个大写字母

例如

A examples
&t=clothes&t=bags&s=other&c=US&c=FR&c=GB
&c=NL
&t=glasses
&c=US&c=FR&c=GB&t=watches&t=necklaces&s=other&s=required

B column (c= strings)
US, FR, GB
C column (t= strings)
clothes,bags
D column (s= strings)
other, required

4 个答案:

答案 0 :(得分:3)

尝试

=join(",", split(mid(A1, find("&c=", A1)+3, len(A1)), "&c="))

enter image description here

答案 1 :(得分:2)

=REGEXEXTRACT(SUBSTITUTE(A1,"&c=",","),"((?:[A-Z]{2},?)+)")
=REGEXREPLACE(REGEXREPLACE(A1,"([^A-Z]*)([A-Z]{2})([^A-Z]*)","$2, "),".$",)
  • [A-Z]任意2个字母的大写单词
  • [^ A-Z]不是2个字母的大写单词

答案 2 :(得分:2)

根据您的输入,您可以决定遵循以下逻辑:将所有字母都大写并用空格分隔。在标准的美国/英国字母中,UpperCase中的字母为26,在ASCII表中介于65和90之间。

因此,从每个值循环并检查它是否在65到90之间是可以的:

Public Function GetUpperCase(inputVal As String) As String

    Dim resultVal As String
    Dim i As Long

    For i = 1 To Len(inputVal)
        If Asc(Mid(inputVal, i, 1)) >= 65 And Asc(Mid(inputVal, i, 1)) <= 90 Then
            resultVal = resultVal & Mid(inputVal, i, 1)
        Else
            resultVal = resultVal & " "
        End If
    Next i

    GetUpperCase = WorksheetFunction.Trim(resultVal)

End Function

最后,WorksheetFunction.Trim非常方便,因为它删除了多个空格并将其减少为一个空格:

enter image description here

答案 3 :(得分:1)

我更喜欢Jeeped的解决方案,但是如果您正在寻找VBA实现。

Private Sub parse_c()
    Dim result As String
    Dim lr As Long

    lr = Cells(Rows.Count, 1).End(xlUp).Row
    result = ""

    For Each cell In Range("A1:A" & lr)
        For i = 1 To Len(cell)
            If (Mid(cell, i, 2) = "c=") Then
                If (result = "") Then
                    result = Mid(cell, i + 2, 2)
                Else
                    result = result & ", " & Mid(cell, i + 2, 2)
                End If
            End If
        Next i
        cell.Offset(0, 1) = result
        result = ""
    Next cell

End Sub
  

在A列中的所有活动单元格中循环,并用所需的分隔符减去所有国家/地区。

已测试:(也有些欺骗,例如=cc=UK

enter image description here