-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
19 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()}") |