简体   繁体   English

将列中的文本分为两列(文本和数字) - Google 工作表或 Excel

[英]Divide text in the column into two columns (text and numbers) - Google sheet or Excel

I have a document in google sheets and the column consists of the name and version, like NLog.Config.4.3.0, NLog.Config.4.4.9 and so on.我在谷歌表格中有一个文档,该列由名称和版本组成,如 NLog.Config.4.3.0、NLog.Config.4.4.9 等。 See the image below for other examples.有关其他示例,请参见下图。

I need to divide this into two columns - name and version, but I'm not familiar with regular expressions so close that I can get this info.我需要将其分为两列 - 名称和版本,但我对正则表达式并不熟悉,以至于我可以得到这些信息。

I can use excel and then import it to the Google doc, it doesn't matter for me how to do that.我可以使用 excel 然后将其导入到 Google 文档中,对我来说如何做到这一点并不重要。

enter image description here在此处输入图像描述

You can try something like this:你可以尝试这样的事情:

Suppose you have your string in A1, then in B1 you can enter this:假设你在 A1 中有你的字符串,那么在 B1 中你可以输入:

=LEFT(A1,LEN(A1)-MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A1&"0123456789")))

and in C1 this:在 C1 中:

=RIGHT(A1,LEN(A1)-MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A1&"0123456789"))+1)

you may need to do some adjustments if there are cases without numbers as it will produce an error, for example you can round it with an Iferror like this:如果有没有数字的情况,您可能需要进行一些调整,因为它会产生错误,例如,您可以使用 Iferror 将其四舍五入,如下所示:

=IFERROR(LEFT(A1,LEN(A1)-MIN(SEARCH({0,1,2,3,4,5,6,7,8,9},A1&"0123456789"))),A1)

Note: A1&"0123456789" is a 'trick' to avoid the search to return error, as the search is looking for all the numbers in the array;注意: A1&"0123456789" 是避免搜索返回错误的“技巧”,因为搜索正在查找数组中的所有数字; we just need the position of the first one, thus the MIN().我们只需要第一个的 position,即 MIN()。

Supposing that your raw data were in A2:A, place this in B2:假设您的原始数据在 A2:A 中,请将其放在 B2 中:

=ArrayFormula(IFERROR(REGEXEXTRACT(A2:A,"(\D+)\.(.+)"),A2:A))

The regular expression reads "Extract any number of non-digits up to but not including a period as group one, and everything remaining into group two."正则表达式读取“提取任意数量的非数字,但不包括句点作为第一组,其余的所有内容都进入第二组。” (In other words, "As soon as you run into a digit after a period, start group two.") (换句话说,“一旦你在一段时间后遇到一个数字,就开始第二组。”)

The IFERROR clause means, "If this pattern can't be found, just return the original cell data." IFERROR子句的意思是,“如果找不到此模式,则返回原始单元格数据。”

Assuming your content is in column A (Google Sheets), try this arrayformula in any cell other than column A :假设您的内容位于A列(Google 表格)中,请在A列以外的任何单元格中尝试此arrayformula

=arrayformula(iferror(split(REGEXREPLACE($A:$A,"(\.)(\d+.+$)",char(6655)&"$2"),char(6655)),))

There are two regex groups denoted in () : ()中表示有两个正则表达式组:

(\.) and (\d+.+$) . (\.)(\d+.+$)

The first group looks for a dot .第一组寻找一个点. - it's escaped using \ . - 它使用\进行了转义。 The second group looks for a number (0-9) \d , one or more occurrences + then ending with $ one or more + of any character .第二组查找一个数字 (0-9) \d ,一次或多次出现+然后以$一个或多次+的任何字符结尾. . .

The replacement is char(6655) (wouldn't usually be found in your dataset), and the contents of group two $2 .替换为char(6655) (通常不会在您的数据集中找到),以及第二组$2的内容。

Then the split function divides the text into two columns by the char(6655) character.然后split function 将文本通过char(6655)字符分成两列。

iferror returns nothing if nothing is split. iferror如果没有拆分任何内容,则不返回任何内容。

The arrayformula works down the sheet. arrayformula在表格中起作用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在Excel VBA中用文本和数字减去两列 - Subtract two columns with text and numbers in excel vba 比较Excel工作表中的两列(文本/字符串),并在第三列中返回匹配的元素 - comparing two columns in excel sheet (text/string) and return the matched element in third column Excel 按文本和数字匹配 2 列 - Excel matching 2 columns by text and numbers 如何在Excel中划分两个带有数字和文本的单元格? - How do you divide two cells in Excel that have numbers and text in them? 我需要在 Excel 工作表中提取文本中的数字 - I need to extract the numbers in a text in an Excel sheet Excel-如何允许文本在受保护的工作表中的列? - Excel - How to allow for Text to Columns in a protected sheet? 将Excel列转换为行(文本数据,而不是数字) - Convert Excel columns into rows (text data, not numbers) 比较两个文本单元格并在Excel工作表2010/2007中显示第三列的差异 - Comparing two text cells and show the differnce in third column in Excel sheet 2010/2007 将一个Excel工作表中的两列与另一工作表中的两列进行比较,如果匹配,则从另一列中复制数据 - Comparing two columns in one Excel sheet, to two columns in another sheet, and if they match, copy data from another column 将文本从Excel中的一张纸拉到另一张纸进行汇总(而不是数字)的公式 - Formula to pull text from one sheet in excel to another to summarize (not numbers)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM