https://docs.python.org/3/library/re.html#re.findall
Findall returns lists of tuples, with each tuple representing the groups from one match. You are grouping the whitespaces but you're not grouping the actual digits.
Try a regex that groups the digits too:
r"(\+420)?(\s*)?(\d{3})(\s*)?\(d{3})(\s*)?\(d{3})"
E.g.
def detect_numbers(text):
phone_regex = re.compile(r"(\+420)?\s*?(\d{3})\s*?(\d{3})\s*?(\d{3})")
print(phone_regex.findall(text))
detect_numbers("so I need to match +420 123 123 123, also 123 123 123, also +420123123123 and also 123123123. Can y")
prints:
[('+420', '123', '123', '123'), ('', '123', '123', '123'), ('+420', '123', '123', '123'), ('', '123', '123', '123')]
You could then string-join the group matches to get the numbers, e.g.
def detect_numbers(text):
phone_regex = re.compile(r"(\+420)?\s*?(\d{3})\s*?(\d{3})\s*?(\d{3})")
groups = phone_regex.findall(text)
for g in groups:
print("".join(g))
detect_numbers("so I need to match +420 123 123 123, also 123 123 123, also +420123123123 and also 123123123. Can y")
prints:
+420123123123
123123123
+420123123123
123123123