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
+ #EJERCICIO
17
+
18
+ def find_numbers (text : str ) -> list :
19
+ return re .findall (r"[0-9]+" , text )
20
+
21
+ print (find_numbers ("Este es el ejercicio 16." ))
22
+
23
+ #DIFICULTAD EXTRA
24
+
25
+ def email_check (email : str ) -> bool :
26
+ return bool (re .match (r"^[\w.+-]+@[\w]+\.[a-zA-Z]+$" , email ))
27
+
28
+ print (
email_check (
"[email protected] " ))
29
+ print (email_check ("ropeda98@gmailcom" ))
30
+
31
+ def phone_number_check (phonenumber : str ) -> bool :
32
+ return bool (re .match (r"^[+]?[\d\s]{3,}$" , phonenumber ))
33
+
34
+ print (phone_number_check ("444444444" ))
35
+ print (phone_number_check ("444 44 44 44" ))
36
+ print (phone_number_check ("+44 4444444" ))
37
+ print (phone_number_check ("4" ))
38
+
39
+ def url_check (url : str ) -> bool :
40
+ return bool (re .match (r"^http[s]?://(www.)?[\w]+\.[a-zA-Z]+$" , url ))
41
+
42
+ print (url_check ("https://klajsdlkas.com" ))
43
+ print (url_check ("http://klajsdlkas.com" ))
44
+ print (url_check ("http://www.klajsdlkas.com" ))
45
+ print (url_check ("http://klajsdlkas" ))
0 commit comments