为什么当期望返回1行多列的数组时,REGEXEXTRACT返回单个值? [英] Why is REGEXEXTRACT returning a single value when it is expected to return an array of 1 row and multiple columns?

查看:78
本文介绍了为什么当期望返回1行多列的数组时,REGEXEXTRACT返回单个值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Google Spreadsheets中的矩阵管理功能非常方便,并且与处理正则表达式(例如REGEXMATCH和REGEXEXTRACT等)的功能相结合,使其特别有用.

The matrix management feature in Google Spreadsheets is convenient and combined with functions that handle regular expressions like REGEXMATCH and REGEXEXTRACT, among others, makes it especially useful.

我遇到一种情况,我不知道由于什么原因而无法得到预期的结果.这是我想要做的:

I have a case in which I do not know what is due that does not give the expected result. Here's what I'm trying to do:

电子表格设置
区域设置:墨西哥,使用.(点)作为小数点分隔符.

Spreadsheet Settings
Regional Settings: Mexico, use . (dot) as decimal separator.

条目
A1:abcde

Entry
A1: abcde

公式
B1:=ArrayFormula(REGEXEXTRACT(A1,{".{1}",".{2}"}))

Formula
B1: =ArrayFormula(REGEXEXTRACT(A1,{".{1}",".{2}"}))

预期结果
B1:a
B2:ab

Expected result
B1: a
B2: ab

获得的结果
B1:a
B2:

Obtained result
B1: a
B2:

已知的解决方法
=ArrayFormula(TRANSPOSE(REGEXEXTRACT(A1,{".{1}";".{2}"})))

此问题也已发布在西班牙语网站上-> https://es.stackoverflow.com/q/55704/65

This question also has being posted on the Spanish site -> https://es.stackoverflow.com/q/55704/65

推荐答案

Quoting Jean-Pierre Verhulst on a similar case in REGEXEXTRACT Array Mysteriously Stopped Working Today (Google Docs Help Forum):

团队非常了解此问题,应尽快进行修复.

The team is well aware of the issue and a fix should be there soon.


巧合的是,它于2017年1月4日发布,同一天
AdamL 修改了他对


Coincidentally, it was published Jan 4th, 2017, the same date AdamL modified his answer to ARRAYFORMULA() does not work with SPLIT(), explaining that:

REGEXEXTRACT似乎不再支持第二个参数的数组.

REGEXEXTRACT no longer appears to support an array for the second argument.



我们可以得出结论, ArrayFormula中的此行为是由于Google表格中的修改所致,允许在数组公式中使用SPLIT,结果是REGEXEXTRACT不接受多列作为正则表达式中的输入.



We can conclude that this behaviour in ArrayFormula is due to a modification in Google Sheets, allowing SPLIT in array formulas, with the consequence of REGEXEXTRACT not accepting multiple columns as input in the regex.

这可能是因为REGEXEXTRACT在正则表达式中具有多个捕获组会产生一个水平数组,每个组一个单元格.以数组作为参数,其行为可能是不确定的,但这对我而言很简单.

This is probably because REGEXEXTRACT, with multiple capture groups in the regular expression, yields an horizontal array, one cell for each group. Having an array as argument, the behaviour may be undefined, but that is plain argumentative on my side.

这篇关于为什么当期望返回1行多列的数组时,REGEXEXTRACT返回单个值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆