Skip to content

Commit c8ef3b0

Browse files
authored
Merge pull request #9036 from Irenetitor/pr/16-Python
#16-Python
2 parents 631c464 + 7da46ba commit c8ef3b0

File tree

1 file changed

+38
-0
lines changed

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+
import re
2+
3+
#Exercise
4+
5+
regex = r"[0-9]+" #same "/d+"
6+
7+
text = "Yesterday I walked 7 kilometers and drank 2 liters of water before 8:30 PM."
8+
9+
def find_numbers(text: str) -> list:
10+
return re.findall(regex, text)
11+
12+
print(find_numbers(text))
13+
14+
#Extra exercise
15+
16+
#r"[a-zA-Z0-9_.]+" == r"[\w]+"
17+
18+
def validate_email(email: str) -> bool:
19+
pattern = r"^[\w.+-]{3,40}@[A-Za-z0-9-]{2,7}\.[A-Za-z]{2,6}$"
20+
return bool(re.match(pattern, email))
21+
22+
print(validate_email("[email protected]"))
23+
24+
def val_phone_num(num: str) -> bool:
25+
pattern2 = r"^\+?\d{1,3}?[- ]?\d{7,14}$"
26+
return bool(re.match(pattern2, num))
27+
28+
print(val_phone_num("+34123456789"))
29+
print(val_phone_num("+1-234567890"))
30+
print(val_phone_num("0123456789"))
31+
32+
def validate_url(url: str) -> bool:
33+
pattern3 = r"^(https?|ftp)://[A-Za-z0-9.-]{2,56}\.[A-Za-z]{2,8}$"
34+
return bool(re.match(pattern3, url))
35+
36+
print(validate_url("http://domain"))
37+
print(validate_url("http://google.es"))
38+
print(validate_url("ftp://my-site123.org"))

0 commit comments

Comments
 (0)