Skip to content

Instantly share code, notes, and snippets.

@ZhouYang1993
Created April 19, 2020 22:39
Show Gist options
  • Save ZhouYang1993/a088d2c1223f817ea7f85a536505b294 to your computer and use it in GitHub Desktop.
Save ZhouYang1993/a088d2c1223f817ea7f85a536505b294 to your computer and use it in GitHub Desktop.
Regex in Python
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