File tree Expand file tree Collapse file tree 1 file changed +39
-0
lines changed
Roadmap/16 - EXPRESIONES REGULARES/python Expand file tree Collapse file tree 1 file changed +39
-0
lines changed Original file line number Diff line number Diff line change 1+ import re
2+
3+ # Ejercicio
4+
5+
6+ def find_numbers_in_string (text : str ) -> list :
7+ regex = r"\d+"
8+
9+ return re .findall (regex , text )
10+
11+
12+ # Extra
13+
14+
15+ def validate_email (email : str ) -> bool :
16+ regex = r"^[\w_.+-]+@[\w-]+\.[a-zA-Z.]+$"
17+ return bool (re .match (regex , email ))
18+
19+
20+ def validate_phone_number (phone_number : str ) -> bool :
21+ regex = r"^\+\d{2}\s{1}[\d{2}\s?\-?}]+$"
22+ return bool (re .match (regex , phone_number ))
23+
24+
25+ def validate_url (url : str ) -> bool :
26+ regex = r"^(https?:\/\/)?((www.)?[a-zA-Z0-9.-]+)\.([a-zA-Z]{2,})([\/\w .-]*)*\/?$"
27+ return bool (re .match (regex , url ))
28+
29+
30+ if __name__ == "__main__" :
31+ text = "Este es el ejercicio 16 publicado el 15/04/2024"
32+ print (find_numbers_in_string (text ))
33+
34+ 35+ print (validate_email (email ))
36+ phone = "+52 5523458970"
37+
38+ url = "http://www.midominio.com.mx/sitio/mundo"
39+ print (validate_url (url ))
You can’t perform that action at this time.
0 commit comments