12.14. Group Work: Regular Expressions (Regex)

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.

Note

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.

Learning Objectives

Students will know and be able to do the following.

Content Objectives:

12.14.1. Regex Methods

Two of the methods that you can use with regular expressions are search and findall. Note that you must import re to use these.

Run the code below to see what it prints.

12.14.2. Quantifiers

You can specify how many items to match using quantifiers. They refer to the item to their left. The quantifiers are ?, +, *, {n}, and {n,m}.

Run the code below to see what it prints.

12.14.3. Character Sets

You can use [] to specify that you need to match any one item in the [].

Run the code below to see what it prints.

12.14.4. Character Ranges

You can specify a range of items to match.

Run the code below to see what it prints.

12.14.5. Character Classes

Run the code below to see what it prints.

Run the code below to see what it prints.

12.14.6. Escaping Special Characters

If you want to match something that is normally a special character in regex you must escape it by adding a \ in front of it.

Run the code below to see what it prints.

12.14.7. Greedy and Non-Greedy Matching

Matching is usually greedy.

Run the code below to see what it prints.

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.

You have attempted of activities on this page