![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How do we use re.finditer() method in Python regular expression?
According to Python docs,
re.finditer(pattern, string, flags=0)
Return an iterator yielding MatchObject instances over all non-overlapping matches for the RE pattern in string. The string is scanned left-to-right, and matches are returned in the order found. Empty matches are included in the result.
The following code shows the use of re.finditer() method in Python regex
Example
import re s1 = 'Blue Berries' pattern = 'Blue Berries' for match in re.finditer(pattern, s1): s = match.start() e = match.end() print 'String match "%s" at %d:%d' % (s1[s:e], s, e)
Output
Strings match "Blue Berries" at 0:12
Advertisements