Skip to content

Commit 94beef9

Browse files
committed
mouredev#16 - python
1 parent fd3aa71 commit 94beef9

File tree

1 file changed

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

1 file changed

+38
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+

0 commit comments

Comments
 (0)