Regex for splitting a german address into its parts

前端 未结 6 756
孤街浪徒
孤街浪徒 2021-02-09 18:09

Good evening,

I\'m trying to splitting the parts of a german address string into its parts via Java. Does anyone know a regex or a library to do this? To split it like t

6条回答
  •  伪装坚强ぢ
    2021-02-09 18:38

    At first glance it looks like a simple whitespace would do it, however looking closer I notice the address always has 4 parts, and the first part can have whitespace.

    What I would do is something like this (psudeocode):

    address[4] = empty
    split[?] = address_string.split(" ")
    address[3] = split[last]
    address[2] = split[last - 1]
    address[1] = split[last - 2]
    address[0] = join split[first] through split[last - 3] with whitespace, trim trailing whitespace with trim()
    

    However, this will only handle one form of address. If addresses are written multiple ways it could be much more tricky.

提交回复
热议问题