I have task to be done. I have test file for it which is containing code:
import unittest
from Task302 import extract_minutes
class Task302Test(unittest.TestCase):
"""Testy do zadania 302"""
def test_simple(self):
"""Prosty test."""
self.assertEqual(extract_minutes("9:13"), "13")
self.assertEqual(extract_minutes("18:44"), "44")
self.assertEqual(extract_minutes("23:59"), "59")
self.assertEqual(extract_minutes("0:00"), "00")
self.assertEqual(extract_minutes("25:14"), "<NONE>")
self.assertEqual(extract_minutes("9:61"), "<NONE>")
self.assertEqual(extract_minutes("x9:13y"), "<NONE>")
I have written code:
def extract_minutes(string):
pattern = '[0-1]*[0-9]+|2[0-3]:([0-5][0-9])'
r = re.compile(pattern)
m = r.search(string)
if m:
return m.group(1)
else:
return "<NONE>"
Please explain me what is wrong with my code and how to fix it.
2[0-3]:([0-5][0-9])part of your regex won't match the starting9. That's what i explained.