The correct answer is the list `['support@example.com', 'sales@example.org']` because `re.findall()` scans the entire string and returns all non-overlapping matches of the regex pattern `r'\b\w+@\w+\.\w{2,4}\b'`. This pattern uses `\b` for word boundaries to ensure the email is isolated, `\w+` for the local part and domain name, and `\w{2,4}` to match common top-level domains like .com and .org. On the PCAP exam, this tests your understanding of the `re` module’s `findall()` method and how to construct patterns for real-world data extraction—a frequent task in the “Regular Expressions” domain. A common trap is forgetting that `findall()` returns a list of strings, not match objects, or using `re.search()` which only returns the first match. Memory tip: think of `findall()` as a “find all” net that catches every valid email in the text, while the pattern’s `\b` bookends act like parentheses keeping each address whole.
PCAP Strings Practice Question
This PCAP practice question tests your understanding of strings. Read the scenario carefully and evaluate each option against the stated constraints before committing to an answer. After answering, compare your reasoning against the explanation and wrong-answer breakdown below. Once you have made your selection, read the full explanation to reinforce the concept and understand why each distractor is designed to mislead on exam day.
Exhibit
Refer to the exhibit.
```python
import re
pattern = r'\b\w+@\w+\.\w+\b'
text = 'Contact us: support@example.com or sales@example.org.'
matches = re.findall(pattern, text)
print(matches)
```
Refer to the exhibit.
```python
import re
pattern = r'\b\w+@\w+\.\w+\b'
text = 'Contact us: support@example.com or sales@example.org.'
matches = re.findall(pattern, text)
print(matches)
```
A
['support@example', 'sales@example']
Why wrong: The pattern includes the dot and domain extension, so full addresses are matched.
B
[]
Why wrong: The pattern matches the given text.
C
['support@example.com', 'sales@example.org']
Both email addresses match the pattern.
D
['support@example.com']
Why wrong: Both addresses match; findall returns all.
Answer the question above first, then reveal the full breakdown to understand why each option is right or wrong.
Correct answer & explanation
✓
['support@example.com', 'sales@example.org']
The code uses `re.findall()` with the pattern `r'\b\w+@\w+\.\w{2,4}\b'`. This pattern matches word boundaries, one or more word characters, an '@', one or more word characters, a dot, and 2-4 word characters (the TLD). The string contains 'support@example.com' and 'sales@example.org', both of which satisfy the pattern, so they are returned as a list. Option C is correct because the regex correctly extracts both email addresses.
Key principle: Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.
Answer analysis
Option-by-option breakdown
For each option: why learners choose it and why it is or isn't the right answer here.
✗
['support@example', 'sales@example']
Why it's wrong here
The pattern includes the dot and domain extension, so full addresses are matched.
✗
[]
Why it's wrong here
The pattern matches the given text.
✓
['support@example.com', 'sales@example.org']
Why this is correct
Both email addresses match the pattern.
Related concept
Read the scenario before looking for a memorised answer.
✗
['support@example.com']
Why it's wrong here
Both addresses match; findall returns all.
Common exam traps
Common exam trap: answer the scenario, not the keyword
Python Institute often tests the misconception that `re.findall()` returns only the first match or that the regex fails due to the dot not being escaped, but here the dot is correctly escaped with `\.` and the pattern matches all occurrences, so candidates who think the dot is a wildcard or that the pattern is invalid may incorrectly choose B or D.
Detailed technical explanation
How to think about this question
The `\b` word boundary anchors ensure the match starts and ends at a word/non-word transition, preventing partial matches like 'support@example.com' inside a longer string. The `\w` character class matches letters, digits, and underscores, so the pattern would also match emails with underscores or digits in the local part or domain. In real-world scenarios, this regex is simplistic because it does not account for hyphens, subdomains, or special characters in email addresses, but it suffices for basic extraction from clean text.
KKey Concepts to Remember
Read the scenario before looking for a memorised answer.
Find the constraint that changes the correct option.
Eliminate answers that are true in general but not in this case.
TExam Day Tips
→Watch for words such as best, first, most likely and least administrative effort.
→Review why wrong options are wrong, not only why the correct option is correct.
Key takeaway
Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option.
Real-world example
How this comes up in practice
A cloud solutions architect for a retail company is evaluating services for a new workload. The correct answer here reflects best practice for the specific scenario described — not a general cloud recommendation. Answer the scenario, not the keyword: identify the specific constraint before choosing the most familiar-sounding option. Cloud exam questions reward reading the constraint carefully: the same technology can be right or wrong depending on the use case.
What to study next
Got this wrong? Here's your next step.
Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.
Strings — This question tests Strings — Read the scenario before looking for a memorised answer..
What is the correct answer to this question?
The correct answer is: ['support@example.com', 'sales@example.org'] — The code uses `re.findall()` with the pattern `r'\b\w+@\w+\.\w{2,4}\b'`. This pattern matches word boundaries, one or more word characters, an '@', one or more word characters, a dot, and 2-4 word characters (the TLD). The string contains 'support@example.com' and 'sales@example.org', both of which satisfy the pattern, so they are returned as a list. Option C is correct because the regex correctly extracts both email addresses.
What should I do if I get this PCAP question wrong?
Identify which exam domain this question belongs to, review the core concept, then practise similar questions from the same domain.
What is the key concept behind this question?
Read the scenario before looking for a memorised answer.
About these practice questions
Courseiva creates original exam-style practice questions with explanations and wrong-answer analysis. It does not publish real exam questions, exam dumps, or protected exam content. Learn why practice questions differ from exam dumps →
Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.
This PCAP practice question is part of Courseiva's free Python Institute certification practice question bank. Courseiva provides original exam-style practice questions with explanations, topic-based practice, mock exams, readiness tracking, and study analytics to help learners prepare for the PCAP exam.
Question Discussion
Share a tip, memory trick, or ask about the reasoning behind this question. Do not post real exam questions, leaked content, braindumps, or copyrighted exam material. Comments are moderated and may be removed without notice.
Sign in to join the discussion.