Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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. image text in transcribed

la. (2 pts) Write a regular expression pattem that matches times on a 12-hour clock 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 Put your answer in repatternl.txt. lb. (3 pts) Write a regular expression patterm that matches the same strings described in part la. But in addition for this patterm, 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:23pn') then m. groups() retums ('6', '23', None, 'pm'). There should be no other numbered groups. Hint (2...) creates a parenthesized regular expression that is not numbered as a group. You can write one regular expression for both la and 1b, or you can write a simpler one for la (ignore groups) and then update it for lb by including the necessary groups. Put your answer in repatternlb.txt. la. (2 pts) Write a regular expression pattem that matches times on a 12-hour clock 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 Put your answer in repatternl.txt. lb. (3 pts) Write a regular expression patterm that matches the same strings described in part la. But in addition for this patterm, 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:23pn') then m. groups() retums ('6', '23', None, 'pm'). There should be no other numbered groups. Hint (2...) creates a parenthesized regular expression that is not numbered as a group. You can write one regular expression for both la and 1b, or you can write a simpler one for la (ignore groups) and then update it for lb by including the necessary groups. Put your answer in repatternlb.txt

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Driven Web Sites

Authors: Mike Morrison, Joline Morrison

1st Edition

061901556X, 978-0619015565

More Books

Students also viewed these Databases questions