-
-
Save christiaanwesterbeek/c574beaf73adcfd74997 to your computer and use it in GitHub Desktop.
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
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
@Remco75 het is wellicht nog niet perfect maar https://github.com/NoxxieNl/Nladdresslexer