Question
PYTHON REGULAR EXPRESSIONS (1A and 1B are related to each other, please answer ALL parts) write and submit a one line file. The line should
PYTHON REGULAR EXPRESSIONS (1A and 1B are related to each other, please answer ALL parts)
write and submit a one line file. The line should start with the ^ character and end (on the same line) with the $ character. The contents of that one line should be exactly what you typed-in/tested in the online Regular Expression checker.
1a) Write a regular expression pattern that matches times on a 12-hour clock written in the formathour: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:ShouldNotMatch:6, 06pm, 14pm, 6::pm, 6:60pm, 6:111pm, 6:4pm, 6:04:7pm, 6:23:15:23am
1b)Write a regular expression pattern that matches the same strings described in part 1a. But 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 executem = re.match(the-pattern, '6:23pm) then m.groups() returns ('6', '23', None, 'pm'). There should be no other numbered groups. Hint (?:...) creates a parenthesized regular expression that is not numbered as a group.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started