File tree Expand file tree Collapse file tree 1 file changed +38
-0
lines changed
Roadmap/16 - EXPRESIONES REGULARES/python Expand file tree Collapse file tree 1 file changed +38
-0
lines changed Original file line number Diff line number Diff line change 1+ # EJERCICIO:
2+ # Utilizando tu lenguaje, explora el concepto de expresiones regulares,
3+ # creando una que sea capaz de encontrar y extraer todos los números
4+ # de un texto.
5+
6+ import re
7+
8+ text = "Hola, 12 de cada 20 animales están abandocnados en una calle"
9+
10+ patron = r"\d+"
11+
12+ nums = re .findall (patron , text )
13+ print (nums )
14+
15+ # DIFICULTAD EXTRA (opcional):
16+ # Crea 3 expresiones regulares (a tu criterio) capaces de:
17+ # - Validar un email.
18+ # - Validar un número de teléfono.
19+ # - Validar una url.
20+
21+
22+ def re_web (text : str ):
23+ re_url = r"^(www)\.[a-z0-9.+-]+\.[a-z]{2,10}$"
24+ is_web = bool (re .fullmatch (re_url , text ))
25+ return is_web
26+
27+
28+ def re_telephon_number (phone : str ):
29+ re_phone = r"^\d{9}$"
30+ is_phone = bool (re .fullmatch (re_phone , phone ))
31+ return is_phone
32+
33+
34+ def re_mail (mail : str ):
35+ re_mail = r"^[A-Za-z0-9.+-]+@[A-Za-z0-9.+-]+\.[A-Za-z]{2,63}$"
36+ is_mail = bool (re .fullmatch (re_mail , mail ))
37+ return is_mail
38+
You can’t perform that action at this time.
0 commit comments