Created
April 19, 2020 22:35
-
-
Save ZhouYang1993/a0625213f62874288f7829107abf3a29 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') show all groups(substrings) | |
matched.group() | |
# '18:05' group will always be the original string | |
matched.group(0) | |
# '18:05' group(0) will always be 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