From a5b820adfd14dcdfe37941f0c2dd3c34cba630d3 Mon Sep 17 00:00:00 2001 From: Christian Juner Date: Thu, 31 Mar 2022 12:23:21 +0200 Subject: [PATCH] Support block-type streets like in Mannheim, Germany --- src/AddressSplitter.php | 18 ++++++++++++++- tests/AddressSplitterTest.php | 42 +++++++++++++++++++++++++++++++++++ 2 files changed, 59 insertions(+), 1 deletion(-) diff --git a/src/AddressSplitter.php b/src/AddressSplitter.php index 3d1e95b..1091757 100644 --- a/src/AddressSplitter.php +++ b/src/AddressSplitter.php @@ -243,7 +243,23 @@ public static function splitAddress($address) ######################################################################### (?:(?P.*?),\s*(?=.*[,\/]))? # Addition to address 1 (?!\s* ' . $houseNumberPrefixes . ') - (?P[^0-9# ]\s*\S(?:[^,#](?!\b\pN+\s))*?(? + (?: + # Special case for Mannheim, Germany-style ("block") street names with a single letter followed + # by one or more digits. + \pL + \pN+ + ) + | + (?: + # Any other street name. + [^0-9# ] + \s* + \S + (?:[^,#](?!\b\pN+\s))*? + (? (?P diff --git a/tests/AddressSplitterTest.php b/tests/AddressSplitterTest.php index 398519e..977e5c5 100644 --- a/tests/AddressSplitterTest.php +++ b/tests/AddressSplitterTest.php @@ -806,6 +806,48 @@ public function validAddressesProvider() 'additionToAddress2' => '' ) ), + array( + // Example: Mannheim, Germany + 'L14 10', + array( + 'additionToAddress1' => '', + 'streetName' => 'L14', + 'houseNumber' => '10', + 'houseNumberParts' => array( + 'base' => '10', + 'extension' => '', + ), + 'additionToAddress2' => '', + ), + ), + array( + // Example: Mannheim, Germany + 'L1 1', + array( + 'additionToAddress1' => '', + 'streetName' => 'L1', + 'houseNumber' => '1', + 'houseNumberParts' => array( + 'base' => '1', + 'extension' => '', + ), + 'additionToAddress2' => '', + ), + ), + array( + // Example: Mannheim, Germany + 'L14 1', + array( + 'additionToAddress1' => '', + 'streetName' => 'L14', + 'houseNumber' => '1', + 'houseNumberParts' => array( + 'base' => '1', + 'extension' => '', + ), + 'additionToAddress2' => '', + ), + ), ); }