Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/17.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/regex/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Regex 从逗号分隔的cel中只获取X个字符串_Regex_Google Sheets_Spreadsheet - Fatal编程技术网

Regex 从逗号分隔的cel中只获取X个字符串

Regex 从逗号分隔的cel中只获取X个字符串,regex,google-sheets,spreadsheet,Regex,Google Sheets,Spreadsheet,很难找到这个简单问题的简洁解决方案。目前,我的单元格包含许多逗号分隔的项目。我只想要前5个 即A1单元= text, another string, something else, here's another one, guess what another string here, and another, hello i'm another string, another string etc, etc, etccccc 我试着抓住前5根弦 除此之外,我想知道是否可以合并一个公式,例如=L

很难找到这个简单问题的简洁解决方案。目前,我的单元格包含许多逗号分隔的项目。我只想要前5个

即A1单元=

text, another string, something else, here's another one, guess what another string here, and another, hello i'm another string, another string etc, etc, etccccc
我试着抓住前5根弦

除此之外,我想知道是否可以合并一个公式,例如
=LEN(A1)>20

目前我做这件事的人很多<代码>=IFERROR(索引(拆分(C31,”,”,1))然后
=IFERROR(索引(拆分(C31,”,”,2))
等。然后运行上面的LEN公式

有更简单的解决方案吗?非常感谢。

试试看

 =split(replace(A1, find("|", SUBSTITUTE(A1, ", ", "|", 5)), len(A1), ""), ", ", false)
试试看


对于Excel,在A1中输入数据,在B1中输入:

=TRIM(MID(SUBSTITUTE($A1,",",REPT(" ",999)),COLUMNS($A:A)*999-998,999))
并复制到:

要将所有5个子字符串放入单个单元格,请使用:

=LEFT(A1,FIND(CHAR(1),SUBSTITUTE(A1,",",CHAR(1),5))-1)

对于Excel,在A1中输入数据,在B1中输入:

=TRIM(MID(SUBSTITUTE($A1,",",REPT(" ",999)),COLUMNS($A:A)*999-998,999))
并复制到:

要将所有5个子字符串放入单个单元格,请使用:

=LEFT(A1,FIND(CHAR(1),SUBSTITUTE(A1,",",CHAR(1),5))-1)
  • 按分隔符拆分到拆分
  • 数组\u约束以约束数组
  • 正则表达式提取5个逗号分隔的值
    • 任何字符
    • *?
      ,任何字符重复次数不限(
      尽可能少),后跟一个
    • {5}
      量词
  • 重复字符串
  • 按分隔符拆分到拆分
  • 数组\u约束以约束数组
  • 正则表达式提取5个逗号分隔的值
    • 任何字符
    • *?
      ,任何字符重复次数不限(
      尽可能少),后跟一个
    • {5}
      量词
  • 重复字符串

文本到列,并将前五列复制到新页?这需要一个公式吗?另外,因为您使用的是
SPLIT
函数,我假设这是google sheets而不是excel?@tigeravatar抱歉,我不知道SPLIT是google sheets的“东西”,抱歉,是的,我使用的是google sheets。我想我在这里也很出色。谢谢。将文本复制到列并将前五列复制到新的工作表?这需要一个公式吗?另外,因为您使用的是
SPLIT
函数,我假设这是google sheets而不是excel?@tigeravatar抱歉,我不知道SPLIT是google sheets的“东西”,抱歉,是的,我使用的是google sheets。我想我在这里也很出色。谢谢。如果我想把结果放在一个单元格中,我已经计算出我可以使用:=JOIN(替换(B2,find(“|)”,替换(B2,”,“|“,”,4)),len(B2),“),”,”,)如果我想把结果放在一个单元格中,我已经计算出我可以使用:=JOIN(替换(B2,find(“|)”,替换(B2,“,”,“,“,”,替换(B2),“,”,“,”,4)),len(B2),“,”,),,“,”,”,)