[英]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 文档中,对我来说如何做到这一点并不重要。
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.