Skip to content

Commit

Permalink
Adding regex_finditer.py
Browse files Browse the repository at this point in the history
  • Loading branch information
oneananda committed Oct 24, 2024
1 parent 9a73792 commit b61f411
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions 0006-Regular-Expressions-FindIter/regex_finditer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
"""
This program demonstrates the use of the re.finditer function in Python for regular expressions.
It checks for all matches in the string.
"""
# regex_finditer.py

import re

PATTERN = r'\d+'

# String to search
TEXT = "I have 5 baskets and 10 lemons."

# Using finditer() to find all occurrences
MATCHES = re.finditer(PATTERN, TEXT)

# Loop through the matches and print details
for match in MATCHES:
print(f"Found the number {match.group()} at position {match.start()} to {match.end()}")

0 comments on commit b61f411

Please sign in to comment.