Created
April 19, 2020 22:39
-
-
Save ZhouYang1993/a088d2c1223f817ea7f85a536505b294 to your computer and use it in GitHub Desktop.
Regex in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
time='18:05' | |
matched = re.match(r'^(0[0-9]|1[0-9]|2[0-3])\:(0[0-9]|1[0-9]|2[0-9]|3[0-9]|4[0-9]|5[0-9])$', time) | |
matched.groups() | |
# ('18', '05') | |
matched.group() | |
# '18:05' | |
matched.group(0) | |
# '18:05' group(0) returns the original string | |
matched.group(1) | |
# '18' | |
matched.group(2) | |
# '05' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment