KnowledgeHub
Questions
Tags
Users
Search
Alex Rivera
|
Logout
Edit Question
Title
Body
For school I'm supposed to write a Python RE script that extracts IP addresses. The regular expression I'm using seems to work with re.search() but not with re.findall() . exp = "(\d{1,3}\.){3}\d{1,3}" ip = "blah blah 192.168.0.185 blah blah" match = re.search(exp, ip) print match.group() The match for that is always 192.168.0.185, but its different when I do re.findall() exp = "(\d{1,3}\.){3}\d{1,3}" ip = "blah blah 192.168.0.185 blah blah" matches = re.findall(exp, ip) print matches[0] 0. I'm wondering why re.findall() yields 0. when re.search() yields 192.168.0.185, since I'm using the same expression for both functions. And what can I do to make it so re.findall() will actually follow the expression correctly? Or am I making some kind of mistake?
Tags (comma-separated)
Save Edits
Cancel