Skip to content

Instantly share code, notes, and snippets.

@reindert-vetter
Last active December 21, 2017 13:47
Show Gist options
  • Save reindert-vetter/a90fdffe7d452f92d1c65bbf759f6e38 to your computer and use it in GitHub Desktop.
Save reindert-vetter/a90fdffe7d452f92d1c65bbf759f6e38 to your computer and use it in GitHub Desktop.
Split street regex description
/**
* Regular expression used to split street name from house number.
*
* Street (key street)
* (?P<street>.*?)
*
* An Street and house number is sometimes separated by a whitespace
* \s?
*
* Insert number and extension together in one array
* (?P<street_suffix>
*
* Set number (int)
* (?P<number>[\d]+)
*
* Sometimes an extension begins with a dash or a space
* [\s-]{0,2}
*
* Set key for extension
* (?P<extension>
*
* If extension have text, / or whitespace
* [a-zA-Z/\s]{0,5}$
*
* OR(!) extension has a number
* |[0-9/]{0,5}$
*
* OR(!) extension has a letter followed by numbers
* |\s[a-zA-Z]{1}[0-9]{0,3}$
*
* OR(!) extension has a numbers followed by letter
* |\s[0-9]{2}[a-zA-Z]{0,3}$
*
* Close key for extension
* )
*
* Close number and extension together
* )
*
*/
const SPLIT_STREET_REGEX = '~(?P<street>.*?)\s?(?P<street_suffix>(?P<number>[\d]+)-?(?P<number_suffix>[a-zA-Z/\s]{0,5}$|[0-9/]{0,5}$|\s[a-zA-Z]{1}[0-9]{0,3}$))$~';
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment