Last active
June 6, 2024 14:55
-
-
Save christiaanwesterbeek/c574beaf73adcfd74997 to your computer and use it in GitHub Desktop.
Splitsen van een nederlands adres naar straat, huisnummer en toevoeging middels een regular expression. Deutsch-Adressen werden jetzt auch unterstützt.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
let re = /^(\d*[\wäöüß\d '\/\\\-\.]+)[,\s]+(\d+)\s*([\wäöüß\d\-\/]*)$/i | |
let adressen = [ | |
'Dorpstraat 2', | |
'Dorpstr. 2', | |
'Laan 1933 2', | |
'18 Septemberplein 12', | |
'Kerkstraat 42-f3', | |
'Kerk straat 2b', | |
'42nd street, 1337a', | |
'1e Constantijn Huigensstraat 9b', | |
'Maas-Waalweg 15', | |
'De Dompelaar 1 B', | |
'Kümmersbrucker Straße 2', | |
'Friedrichstädter Straße 42-46', | |
'Höhenstraße 5A', | |
'Saturnusstraat 60-75', | |
'Saturnusstraat 60 - 75', | |
'Plein \'40-\'45 10', | |
'Plein 1945 1', | |
'Steenkade t/o 56', | |
'Steenkade a/b Twee Gezusters', | |
'1, rue de l\'eglise' | |
] | |
let matches = adressen.map((adres) => { | |
let match = adres.match(re) | |
return `<td>${adres}</td><td>${match && match.shift() && match.join('</td><td>')}</td>` | |
}) | |
document.write(`<table><tr>${matches.join('</tr><tr>')}</tr></table>`) | |
// jsFiddle version here: https://jsfiddle.net/devotis/3wLv7ex2 | |
// Changes 2017-08-23 | |
// allow / and \ in street names | |
// use es6 and drop the semicolons | |
// refactor code to produce html table |
We figured out a few problems with german addresses, where the house number is a range or even written like 5+6. Here is an updated Regex. RE:
^(\d*[\p{L}\d '\/\\\-\.]+?)[,\s]+((?:\d+)\s*(?:[\p{L}\d\/]*(?:\s*[-+]\s*[\p{L}\d\-+\/]*)?))$
RE with sample data: https://regex101.com/r/BaQUN4/1 Bye
Here's the python equivalent if anyone is interested:
r"^(\d*[\w\d '\/\\\-\.]+?)[,\s]+((?:\d+)\s*(?:[\w\d\/]*(?:\s*[-+]\s*[\w\d\-+\/]*)?))$"
Beste collega's -g, wanneer het huisnummer + toevoeging bijvoorbeeld 24-2 is, wordt deze niet goed gesplitst in de regex die ik gebruik. De 2 wordt dan als huisnummer gezien. Is hier al een oplossing voor? Groet
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
We figured out a few problems with german addresses, where the house number is a range or even written like 5+6.
Here is an updated Regex.
RE:
^(\d*[\p{L}\d '\/\\\-\.]+?)[,\s]+((?:\d+)\s*(?:[\p{L}\d\/]*(?:\s*[-+]\s*[\p{L}\d\-+\/]*)?))$
RE with sample data: https://regex101.com/r/BaQUN4/1
Bye