Anchors

^ $ and word boundaries.

^ is the start, $ the end, \b a word boundary.

Goal

Keep only lines that start with a date and bound the city name.

import re
print(bool(re.search(r"^Nairobi", "Nairobi 12")))
print(bool(re.search(r"^Nairobi", "kiosk Nairobi")))
import re
print(bool(re.search(r"12$", "Nairobi 12")))
print(bool(re.search(r"12$", "12 units")))
import re
print(re.findall(r"\bNa\w+", "Nairobi banana Nakuru"))
import re
lines = ["2026-01-12 Nairobi 126.0", "note: skip", "2026-01-13 Kisumu 62.0"]
pat = re.compile(r"^\d{4}-\d{2}-\d{2} ")
print([ln for ln in lines if pat.search(ln)])