Skip to content

Commit 10ad24b

Browse files
committed
mouredev#16 - Python
1 parent 12b6809 commit 10ad24b

File tree

1 file changed

+68
-0
lines changed

1 file changed

+68
-0
lines changed
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
'''
2+
* EJERCICIO:
3+
* Utilizando tu lenguaje, explora el concepto de expresiones regulares,
4+
creando una que sea capaz de encontrar y extraer todos los números
5+
de un texto.
6+
7+
* DIFICULTAD EXTRA (opcional):
8+
* Crea 3 expresiones regulares (a tu criterio) capaces de:
9+
- Validar un email.
10+
- Validar un número de teléfono.
11+
- Validar una url.
12+
'''
13+
14+
import re
15+
16+
def find_numbers(text: str) -> list:
17+
return re.findall(r"\d+", text)
18+
19+
numbers = find_numbers("Estoy haciendo el ejercicio 16, hoy es 22/07/2025")
20+
21+
print(f"Numeros encotrados: {numbers}")
22+
23+
'''
24+
Extra
25+
'''
26+
27+
import re
28+
29+
print("🔍 VALIDACIÓN DE FORMATO CON EXPRESIONES REGULARES\n")
30+
31+
# 📧 Validar email
32+
def validate_email(email: str) -> bool:
33+
pattern = r"^[\w\.-]+@[\w\.-]+\.\w{2,}$"
34+
35+
if re.match(pattern, email):
36+
print(f"📧 Email [{email}] → ✅ Válido")
37+
return True
38+
else:
39+
print(f"📧 Email [{email}] → ❌ Inválido")
40+
return False
41+
42+
validate_email("jesusgdev@gmail.com")
43+
44+
# 📞 Validar número de teléfono
45+
def validate_phone(phone: str) -> bool:
46+
pattern = r"^\+?\d{1,3}?[-.\s]?\(?\d{2,4}\)?[-.\s]?\d{3}[-.\s]?\d{4}$"
47+
48+
if re.match(pattern, phone):
49+
print(f"📞 Teléfono [{phone}] → ✅ Válido")
50+
return True
51+
else:
52+
print(f"📞 Teléfono [{phone}] → ❌ Inválido")
53+
return False
54+
55+
validate_phone("+1 426-567-3217")
56+
57+
# 🌐 Validar URL
58+
def validate_url(url: str) -> bool:
59+
pattern = r"^(https?:\/\/)?(www\.)?[\w\-]+\.\w{2,}([\/\w\-\.]*)*\/?$"
60+
61+
if re.match(pattern, url):
62+
print(f"🌐 URL [{url}] → ✅ Válida")
63+
return True
64+
else:
65+
print(f"🌐 URL [{url}] → ❌ Inválida")
66+
return False
67+
68+
validate_url("https://retosdeprogramacion.com/roadmap")

0 commit comments

Comments
 (0)