

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 find the exact positions of each match in Python regular expression?
We use the re.finditer() method to find the exact positions of each match in given string using Python regex
Example
import re p = re.compile("[A-Z0-9]") for m in p.finditer('A5B6C7D8'): print m.start(), m.group()
Output
This gives the output
0 A 1 5 2 B 3 6 4 C 5 7 6 D 7 8
- Related Questions & Answers
- How do we use Python regular expression to match a date string?
- How do we use Python Regular Expression named groups?
- How to match parentheses in Python regular expression?
- How do we use re.finditer() method in Python regular expression?
- Explain Python regular expression search vs match
- Why do we use re.compile() method in Python regular expression?
- How to match at the beginning of string in python using Regular Expression?
- How to match at the end of string in python using Regular Expression?
- How to find all adverbs and their positions in a text using python regular expression?
- How to match a word in python using Regular Expression?
- How to match nonword characters in Python using Regular Expression?
- How to match a whitespace in python using Regular Expression?
- How to match only digits in Python using Regular Expression?
- Why do we use question mark literal in Python regular expression?
- How do I clear the regular expression cache in Python?
Advertisements