Skip to content

Commit b61f411

Browse files
committed
Adding regex_finditer.py
1 parent 9a73792 commit b61f411

File tree

1 file changed

+19
-0
lines changed

1 file changed

+19
-0
lines changed
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"""
2+
This program demonstrates the use of the re.finditer function in Python for regular expressions.
3+
It checks for all matches in the string.
4+
"""
5+
# regex_finditer.py
6+
7+
import re
8+
9+
PATTERN = r'\d+'
10+
11+
# String to search
12+
TEXT = "I have 5 baskets and 10 lemons."
13+
14+
# Using finditer() to find all occurrences
15+
MATCHES = re.finditer(PATTERN, TEXT)
16+
17+
# Loop through the matches and print details
18+
for match in MATCHES:
19+
print(f"Found the number {match.group()} at position {match.start()} to {match.end()}")

0 commit comments

Comments
 (0)