Get data between number two and three delimiter

时间:2016-04-04 17:21:10

标签: google-sheets

I have a large list of people where each person has a line like this.

Bill Gates, IT Manager, Microsoft, <https://www.linkedin.com/in/williamhgates>

I want to extract the company name in a specific cell. In this example, it would be Microsoft, which is between the second and third delimiters (in this case, the delimiter is ", "). How can I do this?

Right now I'm using the split method (=SPLIT(A2, ", ",false)). But it gives me four different cells with information. I would like a command only to output the company in one cell. Can anyone help? I have tried different things, but I can't seem to find anything that works.

Maybe some regex can do it, but I'm not into regex.

3 个答案:

答案 0 :(得分:2)

Short answer

Use INDEX and SPLIT to get the value between two separators. Example

=INDEX(SPLIT(A1,", ",FALSE),2)

Explation

  • SPLIT returns an 1 x n array.
  • The first argument of INDEX could be a range or an array.
  • The second and third arguments of INDEX are optional. If the first parameter is an array that has only one row or one column, it will assume that the second argument corresponds to the larger side of the array, so there is no need to use the third argument.

答案 1 :(得分:0)

A bit nasty, but this formula works, assuming data in cell D3.

=MID(D3,FIND(",",D3,FIND(",",D3)+1)+2,FIND(",",D3,FIND(",",D3,FIND(",",D3)+1)+1)-FIND(",",D3,FIND(",",D3)+1)-2)

Broken down, this is what it does:

  • Take the Mid point of D3 =MID(D3
  • starting two characters after the 2nd comma FIND(",",D3,FIND(",",D3)+1)+2
  • and the number of characters between the 2nd and 3rd comma, excluding spaces FIND(",",D3,FIND(",",D3,FIND(",",D3)+1)+1)-FIND(",",D3,FIND(",",D3)+1)-2)

答案 2 :(得分:0)

我将添加我最喜欢的ArratFormula,您可以使用它自动展开列表,而不会使用draggind公式。假设:

  1. 您的列表包含范围内的数据&#34; A1:A20&#34;
  2. 所有数据都有相同的sintax&#34; ...,公司名称,&lt; ...&#34;
  3. 在这种情况下,您可以使用Arrayformula,粘贴在单元格B1中:

    =ArrayFormula(REGEXEXTRACT(A1:A20,", ([^,]+), <"))
    

    如果您的数据总是看起来像&#34; ...,公司名称,&lt; ...&#34;或者你希望得到不同的输出,在单元格B1中使用这个公式:

    =QUERY(QUERY(TRANSPOSE(SPLIT(JOIN(", ",A1:A20),", ",0)),"offset 2"),"skipping 4")
    

    在这个公式中:

    • offset 2中的2更改为0,1,2,3以获取姓名,职位,公司,链接
    • in skipping 4 4中有许多项目。

    项目数量可按公式计算:

    =len(A1)-len(SUBSTITUTE(A1,",",""))+1
    

    ,最终公式是:

    =QUERY(QUERY(TRANSPOSE(SPLIT(JOIN(", ",A1:A20),", ",0)),"offset 2"),
    "skipping "&len(A1)-len(SUBSTITUTE(A1,",",""))+1)