File tree Expand file tree Collapse file tree 1 file changed +36
-0
lines changed
Roadmap/16 - EXPRESIONES REGULARES/python Expand file tree Collapse file tree 1 file changed +36
-0
lines changed Original file line number Diff line number Diff line change 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+ email = 'johndoe@gmail.com'
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' )
You can’t perform that action at this time.
0 commit comments