Using Pattern.finditer()
then Match.groupdict()
:
>>> import re
>>> s = "bob sue jon richard harry"
>>> r = re.compile('(?P<name>[a-z]+)\s+(?P<name2>[a-z]+)')
>>> [m.groupdict() for m in r.finditer(s)]
[{'name2': 'sue', 'name': 'bob'}, {'name2': 'richard', 'name': 'jon'}]
More Related Contents:
- Match a whole word in a string using dynamic regex
- How to check for valid email address? [duplicate]
- Case insensitive regular expression without re.compile?
- Python string.replace regular expression [duplicate]
- Regex matching 5-digit substrings not enclosed with digits
- How to split but ignore separators in quoted strings, in python?
- Python regex match OR operator
- Regular expression to extract URL from an HTML link
- BeautifulSoup – search by text inside a tag
- Python Regex escape operator \ in substitutions & raw strings
- How to extract an IP address from an HTML string?
- Get the string within brackets in Python
- Regex for existence of some words whose order doesn’t matter
- Split string based on a regular expression
- Python/Regex – How to extract date from filename using regular expression?
- How would I get everything before a : in a string Python
- Python regex: splitting on pattern match that is an empty string
- How to remove symbols from a string with Python? [duplicate]
- Python – Locating the position of a regex match in a string?
- How to find and replace nth occurrence of word in a sentence using python regular expression?
- Python unicode regular expression matching failing with some unicode characters -bug or mistake?
- How to split a string by commas positioned outside of parenthesis?
- Regex to match digits of specific length
- Regex: match only outside parenthesis (so that the text isn’t split within parenthesis)?
- Faster way to remove stop words in Python
- Why doesn’t Python’s `re.split()` split on zero-length matches?
- Extracting matches with the original case used in the pattern during a case insensitive search
- Python regex findall
- Python regex: matching a parenthesis within parenthesis
- Splitting a math expression string into tokens in Python