
- Python Basic Tutorial
- Python - Home
- Python - Overview
- Python - Environment Setup
- Python - Basic Syntax
- Python - Comments
- Python - Variables
- Python - Data Types
- Python - Operators
- Python - Decision Making
- Python - Loops
- Python - Numbers
- Python - Strings
- Python - Lists
- Python - Tuples
- Python - Dictionary
- Python - Date & Time
- Python - Functions
- Python - Modules
- Python - Files I/O
- Python - Exceptions
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 Articles
- How do we find the exact positions of each match in Python's regular expression?
- How do we use Python regular expression to match a date string?
- How do we use Python Regular Expression named groups?
- How do we use re.finditer() method in Python regular expression?
- How to match parentheses in Python regular expression?
- Why do we use re.compile() method in Python 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 a whitespace in python using Regular Expression?
- How to match only digits in Python using Regular Expression?
- Explain Python regular expression search vs match
- How to match at the beginning of string in python using Regular Expression?
- How do we use a delimiter to split string in Python regular expression?
- Why do we use question mark literal in Python regular expression?
- How to match a nonwhitespace character in python using Regular Expression?

Advertisements