Skip to content

Instantly share code, notes, and snippets.

@hidsh
Created December 8, 2011 02:16
Show Gist options
  • Save hidsh/1445786 to your computer and use it in GitHub Desktop.
Save hidsh/1445786 to your computer and use it in GitHub Desktop.
python: re.finditer sample
import re
s = """xxxxx
Hello spam!
Hello Python!
yyyyy"""
match = re.search(r'^Hello (.*)$', s, re.MULTILINE)
for m in re.finditer(r'^Hello (.*)$', s, re.MULTILINE):
print m.groups()
# result:
# ('spam!',)
# ('Python!',)
@farooqkhan003
Copy link

evaluate iterator in different, it took me 2 hours to figure out this error

it = re.finditer(r'^Hello (.*)$', s, re.MULTILINE)
for m in it:
	print m.groups()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment