Created
April 26, 2012 00:18
-
-
Save memee/2494709 to your computer and use it in GitHub Desktop.
regexp
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
>>> resp = """Serial number:<br/> | |
... 353511021287981<br/> | |
... Warranty:<br/> | |
... NO <br/>""" | |
>>> import re | |
>>> patt = re.compile(r'([^>\r]+):.?<br/>.?([^<]+)', re.DOTALL) | |
>>> match = patt.search(resp) | |
>>> match | |
<_sre.SRE_Match object at 0x10535bb58> | |
>>> match.groups(0) | |
('Serial number', '353511021287981') | |
>>> match.groups(1) | |
('Serial number', '353511021287981') | |
>>> match.groups(2) | |
('Serial number', '353511021287981') | |
>>> |
no nie do końca, bez pipki, ale to nic nie zmienia
>>> match.groups(0)
('Serial number', '353511021287981')
>>> match.groups(1)
('Serial number', '353511021287981')
>>> match.groups(2)
('Serial number', '353511021287981')
>>>
no ale dostajesz dokładnie to co chcesz
jest różnica miedzy groups a group
a na dodatek chyba nie search tylko findall
zgaduję...
>>> fa = patt.findall(esp)
>>> fa
[('Serial number', '353511021287981'), ('\nWarranty', 'NO ')]
>>>
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
taką klasę chcesz mieć, tak?