从电子表格单元格中提取特定字符串

Extracting specific string from spreadsheet cell

我有一个 LibreOffice Calc 电子表格,需要从每一行的单元格中提取一个小字符串。这些单元格包含一段文本,看起来与下面类似,但都有不同的单词、长度等。一个常见的事情是我需要提取的文本的实际格式,在这种情况下 17/11/2016 09:00 但可以可以是任何 date/time 格式,如 24h 格式。

Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the 17/11/2016 09:00 industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book.

我已经搜索了以下站点,但无法将它们连接在一起以进行匹配,更不用说提取实际字符串了。

http://regexlib.com/DisplayPatterns.aspx?cattabindex=4&categoryId=5

有人能给我指出正确的方向吗?

公式:

=MID(A1,SEARCH("[:digit:]{2}/[:digit:]{2}/[:digit:]{4} [:digit:]{2}:[:digit:]{2}",A1,1),16)

结果:

17/11/2016 09:00

解释:

为此,请确保在工具 -> 选项 -> LibreOffice Calc -> 计算 -> Enable regular expressions in formulas.

中启用了正则表达式

另一种但类似的方法不需要公式和 returns date/time 索引而不是文本是查找和替换(编辑菜单)使用查找:

(.*)([0-9]{2}/[0-9]{2}/[0-9]{4} [0-9]{2}:[0-9]{2})(.*)

并检查 Other options 下的 Regular expressions

共有三个(组):我们想要的之前的任何东西,我们想要的东西和我们想要的东西之后的任何东西,替换只是第二个捕获组,所以对于替换使用:

 

要匹配的模式是 {2} 任何数字字符 ([0-9]) 后跟 /,另外两个数字和正斜杠,四个数字,space,另外两个数字 : 和两个数字

如果数据在 ColumnA 中,Find/Replace 可能在 ColumnB 中的副本上,以保留源数据。