试图在谷歌电子表格内的arrayformula中拆分

时间:2015-05-12 20:21:23

标签: regex split google-sheets formulas

我正在尝试在google电子表格中使用ARRAYFORMULA函数中的split函数。

我想" 1.2.3.4 "成为" 1 "," 2 "," 3 &# 34;," 4 "

这是单行代码(仅适用于1行)的代码:

=SPLIT(A2;".")

这就是我想要实现的目标(同时处理多行):

//alone
=SPLIT(A2:A;".")

//or with ARRAYFORMULA
=ARRAYFORMULA(SPLIT(A2:A;"."))

由于SPLIT功能无法在ARRAYFORMULA功能中使用,因此我搜索了一种解决方法(ARRAYFORMULA() does not work with SPLIT()):

=ARRAYFORMULA(IFERROR(REGEXEXTRACT("."&A2:A;"^"&REPT(".+[^.]+";COLUMN(OFFSET(A2;;;1;4))-1)&".+([^.]+)")))

它几乎正常工作,除了它没有正确分割的事实,这是我得到的结果:

" 1.2.3.4"成为" 4"," 4"," 4"," 4"

如果我可以让解决方法真正正常工作或更好的替代方案,那将是非常棒的......

2 个答案:

答案 0 :(得分:5)

Your expression creates regular expressions like this:

<Get_People>:
    orientation: 'vertical'
    Button:
        name: root_btn
        id: root_btn
        text: "I am Root Button"
        on_release: change_label_b
    Label:
        id: root_lbl
        text: "I am Root Label"
    Get_Boys:
    Get_Girls:

<Get_Boys>:
    Button:
        id: button_b
        text: "Button for boys"
        on_press: change_label_root
        on_release: change_label_g
    Label:
        id: label_b
        text: "Label for boys"

<Get_Girls>:
    Button:
        id: button_g
        text: "Button for girls"
    Label:
        id: label_g
        text:"Label for girls"

The ^.+[^.]+.+[^.]+.+[^.]+.+([^.]+) part will match anything, as much as possible, thus pushing he last .+ to the end.

If you use an expression like this instead, it should work better:

([^.]+)

It will always count each ^\.[^.]*\.[^.]*\.[^.]*\.([^.]*) , and never push the last group too far.

(You could use . instead of repeating the subpattern, but that would change your original formula too much)

Here is the corresponding formula:

{3}

答案 1 :(得分:-2)

你可以试试这个:

=REGEXREPLACE(A1,"\.","\"",\""")

更新:Google已修复此问题,您现在可以将arrayformula与split:

一起使用

=ArrayFormula(SPLIT(Sheet1!A2:A,"."))