Skip to content

Commit b6d13d9

Browse files
authored
Merge pull request mouredev#6219 from juanchernandezdev/feature
#16 - Python
2 parents ba33942 + 5ab5969 commit b6d13d9

File tree

1 file changed

+36
-0
lines changed

1 file changed

+36
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
### Python Regex ###
2+
import re
3+
4+
pattern = r'\d+'
5+
string = 'this is my test with numbers 1 2 12 45 48'
6+
result = re.findall(pattern, string, re.IGNORECASE)
7+
print(result)
8+
9+
#! Optional Challenge
10+
#* Email
11+
12+
email_pattern = r'^[a-zA-Z0-9._%+-]+@[a-zA-Z0-9.-]+\.[a-zA-Z]{2,6}$'
13+
14+
15+
if re.match(email_pattern, email):
16+
print('Your email is correct')
17+
else:
18+
print('Wrong email format')
19+
20+
#* Phone number US format
21+
phone_pattern = r'^\+?1?\s?\(?\d{3}\)?[\s.-]?\d{3}[\s.-]?\d{4}$'
22+
phone_number = '123 456 7890'
23+
24+
if re.match(phone_pattern, phone_number):
25+
print('Your phone is correct')
26+
else:
27+
print('Wrong phone format')
28+
29+
#* URL
30+
url_pattern = r'^(https?:\/\/)?([a-zA-Z0-9_-]+\.)+[a-zA-Z]{2,6}(:\d+)?(\/[a-zA-Z0-9@:%._\+~#?&\/=-]*)?$'
31+
url_number = "https://www.mytesturl.com"
32+
33+
if re.match(url_pattern, url_number):
34+
print('Your url is correct')
35+
else:
36+
print('Wrong url format')

0 commit comments

Comments
 (0)