match, fullmatch, search

Start of string vs anywhere vs the whole string.

match anchors at the start. fullmatch wants the whole string. search looks anywhere.

Goal

Print how the three functions treat the same kiosk line.

import re
line = "Nairobi 12"
print("match", re.match(r"Nairobi", line))
print("search", re.search(r"12", line))
print("fullmatch", re.fullmatch(r"Nairobi 12", line))
import re
line = "kiosk Nairobi"
print("match 12", re.match(r"12", line))
print("search 12", re.search(r"12", line))
import re
print(bool(re.fullmatch(r"07\d{8}", "0712345678")))
print(bool(re.fullmatch(r"07\d{8}", "0712-345-678")))
import re
pat = r"\d+"
line = "units 12 price 10.5"
print(re.match(pat, line))
print(re.search(pat, line).group())