From 870cbd441140ef1f8972708ba43704f8dd2ed240 Mon Sep 17 00:00:00 2001 From: Pramod Chand Date: Wed, 26 Nov 2025 10:47:00 +0545 Subject: [PATCH] Use re.findall to find all matches of a pattern Replaced re.search with re.findall to find all occurrences of the pattern in the text and added a count of the occurrences. --- Day-02/examples/03-regex-findall.py | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/Day-02/examples/03-regex-findall.py b/Day-02/examples/03-regex-findall.py index ec5cdd5c..251f0b89 100644 --- a/Day-02/examples/03-regex-findall.py +++ b/Day-02/examples/03-regex-findall.py @@ -3,8 +3,9 @@ text = "The quick brown fox" pattern = r"brown" -search = re.search(pattern, text) +search = re.findall(pattern, text) if search: - print("Pattern found:", search.group()) + print("Pattern found:", search) + print("Pattern count:", len(search)) else: print("Pattern not found")