19 lines
553 B
Python
19 lines
553 B
Python
import re
|
|
|
|
|
|
def extract_contacts(text: str) -> dict[str, list[str] | str | None]:
|
|
result: dict[str, list[str] | str | None] = {}
|
|
|
|
result["emails"] = re.findall(
|
|
r"[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,}", text
|
|
)
|
|
|
|
result["phones"] = re.findall(r"\+\d\s\(\d{3}\)\s\d{3}-\d{2}-\d{2}", text)
|
|
|
|
match = re.search(
|
|
r"https?:\/\/(?:www\.)?[-a-zA-Z0-9@:%._\+~#=]{1,256}\.[a-zA-Z0-9()]{1,6}\b(?:[-a-zA-Z0-9()@:%_\+.~#?&//=]*)",
|
|
text,
|
|
)
|
|
result["url"] = match.group() if match else None
|
|
|
|
return result
|