Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

PYTHON PROBLEM 1c. (2 pts) Write a regular expression patterm that matches the s

ID: 3596596 • Letter: P

Question

PYTHON PROBLEM

1c. (2 pts) Write a regular expression patterm that matches the same strings described in part lb. But in addition for this pattern, ensure group 1 is the month; group 2 is the day; group 3 is the year. For example, if we execute m-re.match (the-pattern, '10/13/2017') then m.groups ) returns ('10', 13', '2017'). Likewise, if we execute m = re.match (the-pattern, '10/13') thenn.groups() returns ('10', '13', None): the None is because the optional year part of the pattern is missing: the online tool omits showing such a group. There should be no other numbered groups. Hint (?····) creates a parenthesized regular expression that is not numbered as a group. You can write one regular expression for both lb and lc, or you can write a simpler one for lb (ignore groups) and then update it for lc by specifying the necessary groups. Put your answer in repatternlc.txt.

Explanation / Answer

import re

pattern = r'([1-9]|1[012])/([1-9]|[12][0-9]|3[01])(?:$|/(dddd)$)'

m = re.match(pattern, '10/13/2017')

print(m.groups())

m = re.match(pattern, '10/13')

print(m.groups())

Here is pattern with sample code

# sample execution