0

i'm using the search module but it doesn't work right. when there is one thing that suits what i'm looking for its work good. like:

text = 'lets GET /keyser/22300/ HTTP/1.1 goodbeleive'

match = re.search('GET (.*) HTTP/1.1',text)
match.group(1)

ofcourse i did import re and everything. and i get what i want - the text between GET and HTTP. but when there are some of this pattern its suppossed to take the first one who suitable.. but its takes everything after the HTTP...

text = 'lets GET /keyser/22300/ HTTP/1.1 goodbeleive GET /cyberbit/288/ 
HTTP/1.1therebetter u'

match = re.search('GET (.*) HTTP/1.1',text)
match.group(1)

i get this answer:

'/keyser/22300/ HTTP/1.1 good now beleive GET /cyberbit/288/'

on my program i wanna do a findall to extract all the pattern like this but ofcourse it does not work

please help me if you can give also example to a good-working findall thank you!

Aran-Fey
  • 39,665
  • 11
  • 104
  • 149
Assembly.J
  • 21
  • 6
  • by the way i notice now how to make it more clear for you guys. its take a GET and HTTP as wanted. but the largest one... – Assembly.J Sep 30 '18 at 11:10

1 Answers1

0

You need to make the pattern lazy, by adding a ?.

>>> re.findall(r'GET (.*?) HTTP/1.1', text)
['/keyser/22300/', '/cyberbit/288/']
Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895