我不知道如何将街道号后面的地址分开。
假设地址是以下地址之一:
str='street name, 12B, 1234, The Hague, the Netherlands'
str2='street name 12B 1234AB The Hague, the Netherlands'
str3='street name 12B 1234AB, $ ^ The Hague, the Netherlands'
我想将这些地址拆分为:
1)逗号,最好是非字母/标点符号(例如;^@)。应拆除这些分离器;
2)可以后面跟字母而不删除的数字。
预期结果:
['street name', '12B', '1234', 'The Hague', 'the Netherlands']
我正在尝试str.split(/(\d+[a-z a-z]*)/g)上的变体,它仍然保留类似“,”(为什么?).
我还尝试了分隔符1和2之间的“或”运算符,但没有成功。
这个更接近:
str.split(/(\d+[a-zA-Z]*[,])/g).map(x=>x.trim().replace(/[,.;]/g,''))
[ "street name, ", "12B,", " ", "1234,", " The Hague, the Netherlands" ]