简体   繁体   English

谷歌表格中是否有一种防错方法可以将地址单元格(街道+门牌号)中的门牌号提取到另一个单元格中

[英]Is there an error-proof way in google sheets to extract House numbers from address cell (street + house number) into another cell

In Sheet1:AK2:AK I have addresses in the following formats:Sheet1:AK2:AK我有以下格式的地址:

rotenkamper weg, 323, Kirchstieg 2345, Im Schleedörn 20b

I need the street names to export into Sheet2:C3:C , ie:我需要将街道名称导出到Sheet2:C3:C中,即:

rotenkamper weg, Kirchenstieg, Im Schleedörn

The House numbers have to go into Sheet2:D3:D .门牌号必须 go 到Sheet2:D3:D中。

I have researched and tried for hours but couldn't find a solution that could fetch the house numbers including the letter ie 20b or if the number is a range 24-27 .我已经研究并尝试了几个小时,但找不到可以获取门牌号的解决方案,包括字母 ie 20b或者数字是否在24-27范围内。

Also, I have huge trouble to get it to work when the street consist of two or more words.此外,当街道包含两个或多个单词时,我很难让它工作。

Does anyone know an elegant solution for this?有谁知道一个优雅的解决方案?

Any help would be much appreciated.任何帮助将非常感激。 This will safe me weeks of data entry work.这将保护我数周的数据输入工作。

Try this in Sheet2!C3 :Sheet2!C3中试试这个:

=ARRAYFORMULA(
  {
    REGEXREPLACE(REGEXREPLACE(Sheet1!AK2:AK, "\s+\S*\d\S*\b", ""), ",+", ","),
    IFNA(REGEXEXTRACT(Sheet1!AK2:AK, "\S+$"))
  }
)

Explanation:解释:

  1. REGEXREPLACE(Sheet1:AK2,AK, "\s+\S*\d\S*\b", "") this one removes any "word" which has a digit in it. REGEXREPLACE(Sheet1:AK2,AK, "\s+\S*\d\S*\b", "")这个删除任何包含数字的“单词”。 Al of these 323 , 2345 , 20b will be gone.这些323234520b中的所有都将消失。
  2. REGEXREPLACE(..., ",+", ",") cleans up any multiple consequent commas which may appear after removing in the first step. REGEXREPLACE(..., ",+", ",")清除在第一步中删除后可能出现的任何多个后续逗号。 This will be a value for the first column.这将是第一列的值。
  3. IFNA(REGEXEXTRACT(Sheet1:AK2,AK, "\S+$")) this one just gets whatever is at the end of the address string from the last space to the end. IFNA(REGEXEXTRACT(Sheet1:AK2,AK, "\S+$"))这个只是获取地址字符串末尾从最后一个空格到末尾的任何内容。 This will be a value for the second column.这将是第二列的值。
  4. {value_for_the_first_column, value_for_the_second_column} placed in the C3 cell will populate C3 with value_for_the_first_column and D3 with value_for_the_first_column .放置在C3单元格中的{value_for_the_first_column, value_for_the_second_column}将用value_for_the_first_column填充C3 ,用value_for_the_first_column填充D3
  5. ARRAYFORMULA will do all of the above for every row. ARRAYFORMULA将为每一行执行上述所有操作。

Regex pattern could be refined if you provide more than one example of the address.如果您提供多个地址示例,则可以改进正则表达式模式。

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM