Find Professors' Names Regex Homework Answers Needed
Your Question:
use regular expression in python to find the following:
10 students were enrolled in the first year with Prof. Tom Chan as the chairperson. Professor Xihuang Chen succeeded Prof. Tom Chan and become the chairmanship. Professor Sik-lum Chan was inaugurated as the Department chairman. Professor Lee Yee Lam was inaugurated as the Department chairman.
Professor Lee Yee Lam
Step By Step Answers with Explanation
To find the names of the professors who became chairpersons in the given text using regular expressions in Python, you can use the `re` module. Specifically, we will use the `re.findall()` function to extract the names. Here's a step-by-step explanation of how to achieve this:
# We'll look for the pattern "Professor [First Name] [Last Name]".
pattern = r'Professor ([A-Z][a-z]+ [A-Z][a-z]+)'
print(match)
Output:
Explanation of the code:
1. Import the `re` module for regular expressions.
- `[A-Z][a-z]+`: Matches an uppercase initial letter followed by one or more lowercase letters (first name).
- ` ` (space): Matches the space between the first and last names.