-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaddr_utils.py
More file actions
34 lines (27 loc) · 1.11 KB
/
addr_utils.py
File metadata and controls
34 lines (27 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import re
def strip_unit(full_addr: str) -> str:
"""
Extract the base address without the unit number from an Australian address.
Args:
full_addr: A string containing an Australian address, which may include a unit number.
Returns:
The address without the unit number.
Examples:
>>> strip_unit("14/154 BELLEVUE RD, BELLEVUE HILL 2023")
"154 BELLEVUE RD, BELLEVUE HILL 2023"
>>> strip_unit("56 DUXFORD ST, PADDINGTON 2021")
"56 DUXFORD ST, PADDINGTON 2021"
"""
if not full_addr:
return ""
# Pattern to match unit numbers at the beginning of the address
# This matches patterns like "14/", "1/", "1509/", etc.
unit_pattern = r'^\d+/(?=\d+|\w+|$)'
# Check if the address starts with a unit number
match = re.match(unit_pattern, full_addr)
if match:
# Remove the unit number and return the rest of the address
remainder = full_addr[match.end():]
return remainder if remainder else ""
# If no unit number is found, return the original address
return full_addr