It is best to use a POGIL approach with the following. In POGIL students work in groups on activities and each member has an assigned role. For more information see https://cspogil.org/Home.
If you work in a group, have only one member of the group fill in the answers on this page. You will be able to share your answers with the group at the bottom of the page.
What if you want to match a month from 1 to 12 in MM/DD/YYYY? You canβt use [1-12] since it matches a character at a time. You have to match either a digit from 1 to 9 or a 1 followed by 0, 1, or 2. To use a logical or to match one of two expressions use (left|right). This will match either the expression on the left or the one on the right.
Sometimes dates have a leading zero if the month is from 1 to 9. Which of the following would match that case as well but still match if there isnβt a 0?
Subsection12.15.3Specifying What to Extract - Non-Matching Groups
What if we need the parentheses because we are using a logical or but want the whole match to be returned? We can add a β?:β after the first parenthesis to group items for the logical or but return the entire match.
import re
str = "The dates were 9/11/2022, 10/15/2022, 11/20/2022, and 12/01/2022"
# get the dates
l = []
matches = re.findall("(([1-9]|1[0-2])/\d{2}/\d{4})", str)
for match in matches:
# line to get current date and add to the list
l.append(match)
This would add the tuple not the date
l.extend(match)
Use extend to add two lists together
l.append(match[0])
This will add the date to the list (the first element in the tuple)
Since β\bβ usually represents a backspace in a Python string you must use βrβ before the string to treat it as a raw string. You only need to add the r in front of the string if the expression has a β\bβ in it.
If you worked in a group, you can copy the answers from this page to the other group members. Select the group members below and click the button to share answers.
The Submit Group button will submit the answer for each each question on this page for each member of your group. It also logs you as the official group submitter.