Skip to content

Instantly share code, notes, and snippets.

@memee
Created April 26, 2012 00:18
Show Gist options
  • Save memee/2494709 to your computer and use it in GitHub Desktop.
Save memee/2494709 to your computer and use it in GitHub Desktop.
regexp
>>> 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')
>>>
@romanbarczynski
Copy link

masz klasę znaków []
^ NIE
> znak ">"
| znak "|"
\r znak "\r"

taką klasę chcesz mieć, tak?

@memee
Copy link
Author

memee commented Apr 26, 2012

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')
>>> 

@romanbarczynski
Copy link

no ale dostajesz dokładnie to co chcesz
jest różnica miedzy groups a group

a na dodatek chyba nie search tylko findall

zgaduję...

@romanbarczynski
Copy link

>>> 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