Created
November 10, 2016 13:39
-
-
Save devhero/ad72a5d3631e7d67654bf664026e581e to your computer and use it in GitHub Desktop.
python regex match - http://stackoverflow.com/questions/12870178/looping-through-python-regex-matches
This file contains hidden or 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
import re | |
s = "ABC12DEF3G56HIJ7" | |
pattern = re.compile(r'([A-Z]+)([0-9]+)') | |
# all matches | |
for (letters, numbers) in re.findall(pattern, s): | |
print numbers, '*', letters | |
# It is better to use re.finditer if you dataset is large: | |
for m in re.finditer(pattern, s): | |
print m.group(1), '*', m.group(0) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment