Write a regular expression pattern that matches times on a 12-hour clock written in the format hour:minute:second. Here hour can be any one- or…

  

Write a regular expression pattern that matches times on a 12-hourclock written in the format hour:minute:second. Here hour can be any one- or two-digit number in the range 1-12 (with no leading 0 allowed); :minute is optional: if present it can be any two-digit number in the range 00-59; :second is optional: if present, it can be any two-digit number in the range 00-59; at the end is a mandatory am/pm indicator. Here are a few legal/illegal examples. Legal: Should Match : 6pm, 6:23pm, 6:23:15am, 12am, 11:03am, 8:40:04pm Illegal: Should Not Match: 6, 06pm, 14pm, 6::pm, 6:60pm, 6:111pm, 6:4pm, 6:04:7pm, 6:23:15:23am In addition for this pattern , ensure group 1 is the hour; group 2 is the minute (or None if :minute is not present); group 3 is the second (or None if :second is not present); and group 4 is am or pm. For example, if we execute m = re.match(the-pattern, ‘6:23pm’) then m.groups() returns (‘6′, ’23’, None, ‘pm’). There should be no other numbered groups. Hint (?:…)  I have a python regular expression : ^([1-9][0-2]?):?([0-5][0-9])?:?([0-5][0-9])?(am|pm)$ But I failed to return None when processing 6::pmHow should I change my expression? Computer Science Engineering & Technology Python Programming

Don't use plagiarized sources. Get Your Custom Essay on
Write a regular expression pattern that matches times on a 12-hour clock written in the format hour:minute:second. Here hour can be any one- or…
Just from $13/Page
Order Essay
  

Leave a Reply

Your email address will not be published.

Related Post

Open chat
💬 Need help?
Hello 👋
Can we help you?