Google表格从字符串中提取和求和数值数据

时间:2019-02-27 21:32:35

标签: regex parsing google-sheets find

在google电子表格中,我将以下数据存储在单个单元格中。

a:2:{i:76;a:5:{i:0;a:11:{s:1:"g";s:0:"";s:1:"a";s:0:"";s:2:"st";s:0:"";s:4:"pass";s:0:"";s:2:"pr";s:0:"";s:2:"pu";s:0:"";s:2:"sv";s:0:"";s:2:"sa";s:0:"";s:2:"so";s:0:"";s:4:"poss";s:0:"";s:6:"tended";s:0:"";}i:218;a:14:{s:6:"number";s:0:"";s:1:"g";s:0:"";s:1:"a";s:0:"";s:2:"st";s:0:"";s:4:"pass";s:2:"12";s:2:"pr";s:1:"4";s:2:"pu";s:0:"";s:2:"sv";s:2:"23";s:2:"sa";s:2:"25";s:2:"so";s:0:"";s:4:"poss";s:3:".98";s:6:"tended";s:3:"720";s:6:"status";s:6:"lineup";s:3:"sub";s:1:"0";}i:222;a:14:{s:6:"number";s:0:"";s:1:"g";s:0:"";s:1:"a";s:1:"1";s:2:"st";s:0:"";s:4:"pass";s:2:"14";s:2:"pr";s:2:"17";s:2:"pu";s:2:"33";s:2:"sv";s:0:"";s:2:"sa";s:0:"";s:2:"so";s:0:"";s:4:"poss";s:4:"1.83";s:6:"tended";s:0:"";s:6:"status";s:6:"lineup";s:3:"sub";s:1:"0";}i:237;a:14:{s:6:"number";s:0:"";s:1:"g";s:0:"";s:1:"a";s:0:"";s:2:"st";s:1:"1";s:4:"pass";s:2:"12";s:2:"pr";s:2:"12";s:2:"pu";s:2:"26";s:2:"sv";s:0:"";s:2:"sa";s:0:"";s:2:"so";s:0:"";s:4:"poss";s:4:"1.68";s:6:"tended";s:0:"";s:6:"status";s:6:"lineup";s:3:"sub";s:1:"0";}i:253;a:14:{s:6:"number";s:0:"";s:1:"g";s:1:"1";s:1:"a";s:0:"";s:2:"st";s:1:"4";s:4:"pass";s:2:"12";s:2:"pr";s:2:"17";s:2:"pu";s:2:"29";s:2:"sv";s:0:"";s:2:"sa";s:0:"";s:2:"so";s:0:"";s:4:"poss";s:4:"1.37";s:6:"tended";s:0:"";s:6:"status";s:6:"lineup";s:3:"sub";s:1:"0";}}

我想对分配给每个“通过”字段的所有值求和。

Snippet of Pass Fields     Extracted Data
"pass";s:0:"";                  None
"pass";s:2:"12"                 12
"pass";s:2:"14"                 14
"pass";s:2:"12"                 12
"pass";s:2:"12"                 12
Sum                             50

如果可能,我希望将此计算全部包含在一个单元格中,而不必在电子表格的其他部分中存储临时数据。该公式必须具有足够的动态性,以支持具有不同数量的“ pass”字段的可变长度输入字符串。我尝试使用REGEXEXTRACT / FIND的混合以及各种Google Sheets子字符串函数来隔离这些值,但是使用这些方法,我只能返回分配给第一次出现的值而不是全部都通过。有谁知道我该怎么做?

2 个答案:

答案 0 :(得分:1)

看看是否可行(假设A1中的数据)

=sum(ArrayFormula(regexextract(substitute(A1, char(34),), rept(".+pass;s:\d+:(\d+)", (len(A1)-len(substitute(A1, "pass",)))/4-1))+0))

Screenshot

答案 1 :(得分:0)

尝试使用正则表达式:"pass";s:\d+:"(\d+)"

Demo