Skip to content

Commit 25d4559

Browse files
authored
Merge pull request mouredev#4776 from jptxaya/main
#16 - Python
2 parents 365af85 + a885a2d commit 25d4559

File tree

1 file changed

+50
-0
lines changed
  • Roadmap/16 - EXPRESIONES REGULARES/python

1 file changed

+50
-0
lines changed
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
# #16 EXPRESIONES REGULARES
2+
# /*
3+
# * EJERCICIO:
4+
# * Utilizando tu lenguaje, explora el concepto de expresiones regulares,
5+
# * creando una que sea capaz de encontrar y extraer todos los números
6+
# * de un texto.
7+
# *
8+
# * DIFICULTAD EXTRA (opcional):
9+
# * Crea 3 expresiones regulares (a tu criterio) capaces de:
10+
# * - Validar un email.
11+
# * - Validar un número de teléfono.
12+
# * - Validar una url.
13+
# */
14+
15+
import re
16+
17+
#Ejercicio
18+
texto = "0-Texto a evaluar con 1,2,3 y como maximo 10, es decir un rango de [0-10] numeros para regex"
19+
print(re.findall(r"[0-9]+",texto))
20+
21+
#Dificultad Extra
22+
23+
def validar_email(email:str)->bool:
24+
return bool(re.match(r"^[\w.+-]+@[\w]+\.[a-zA-Z]{2,4}$",email))
25+
26+
print("Validacion email")
27+
print(validar_email("jos@gg.io"))
28+
print(validar_email("jos.sdad@gg.io"))
29+
print(validar_email("jos.sdad@gg.i"))
30+
print(validar_email("jos.sdadgg.io"))
31+
32+
def validar_tlfno(tlfno:str)->bool:
33+
return bool(re.match(r"^\+{0,1}[\d\s]{3,15}$",tlfno))
34+
35+
print("Validacion Tlfno")
36+
print(validar_tlfno("+3411106"))
37+
print(validar_tlfno("666882788"))
38+
print(validar_tlfno("666 88 27 88"))
39+
print(validar_tlfno("66688a788"))
40+
41+
42+
print("Validacion url")
43+
def validar_url(url:str)->bool:
44+
return bool(re.match(r"^https?://(www\.)?[0-9a-zA-Z]*\.[a-zA-Z]{2,}[\w/]*$",url))
45+
46+
print(validar_url("http://hola.com"))
47+
print(validar_url("http://hola.com/1"))
48+
print(validar_url("http://www.hola.com/1"))
49+
print(validar_url("https://www.hola.com/1"))
50+
print(validar_url("hatp://www.hola.com/1"))

0 commit comments

Comments
 (0)