4 ms·
The particular hangup I faced when using regex was with this URL: http://vi.ebaydesc.com/ebaymotors/ws/eBayISAPI.dll?ViewItemDesc&item=290277158797&t=1227377775
by matth 18y ago
The particular hangup I faced when using regex was with this URL:
http://vi.ebaydesc.com/ebaymotors/ws/eBayISAPI.dll?ViewItemDesc&item=290277158797&t=1227377775000&ds=2&seller=la-wheel-and-tire&js=e583:1&hr=http://shop.ebay.com/?_from=R40&caz.html http://vi.ebaydesc.com/ebaymotors/ws/eBayISAPI.dll?ViewItemD...
>>> x = re.compile('(?:(item|t|hr)=(\d+))')
>>> x.findall(url)
[('item', '290277158797'), ('t', '1227377775000')]
I can't for the life of me figure out how to get the hr value. I started messing around with regex again, but no luck so far.
I can do the same with Python's string methods:
>>> hr_start = url.find('hr=')
>>> hr_end = url.find('&',url.find('hr='),len(url))
>>> url[hr_start:hr_end]
'hr=http://shop.ebay.com/?_from=R40' http://shop.ebay.com/?_from=R40'
It's just messy as hell, it'd be nice to do everything in one swoop.
- matth 18y agoOk, mission accomplished methinks: >>> x = re.compile("[\\?&](seller|item|hr)=([^&#]*)") >>> x.findall(url) [('item', '290277158797'), ('seller', 'la-wheel-and-tire'), ('hr', 'http://shop.ebay.com/?_from=R40' http://shop.ebay.com/?_from=R40')]