Skip to content

Commit a7b8cf4

Browse files
committed
#16 - Python
1 parent 86608f0 commit a7b8cf4

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import re
2+
3+
# Ejercicio
4+
5+
6+
def find_numbers_in_string(text: str) -> list:
7+
regex = r"\d+"
8+
9+
return re.findall(regex, text)
10+
11+
12+
# Extra
13+
14+
15+
def validate_email(email: str) -> bool:
16+
regex = r"^[\w_.+-]+@[\w-]+\.[a-zA-Z.]+$"
17+
return bool(re.match(regex, email))
18+
19+
20+
def validate_phone_number(phone_number: str) -> bool:
21+
regex = r"^\+\d{2}\s{1}[\d{2}\s?\-?}]+$"
22+
return bool(re.match(regex, phone_number))
23+
24+
25+
def validate_url(url: str) -> bool:
26+
regex = r"^(https?:\/\/)?((www.)?[a-zA-Z0-9.-]+)\.([a-zA-Z]{2,})([\/\w .-]*)*\/?$"
27+
return bool(re.match(regex, url))
28+
29+
30+
if __name__ == "__main__":
31+
text = "Este es el ejercicio 16 publicado el 15/04/2024"
32+
print(find_numbers_in_string(text))
33+
34+
35+
print(validate_email(email))
36+
phone = "+52 5523458970"
37+
38+
url = "http://www.midominio.com.mx/sitio/mundo"
39+
print(validate_url(url))

0 commit comments

Comments
 (0)