f*cking re module
Matthias Huening
mhuening at zedat.fu-berlin.de
Mon Jul 4 05:06:57 EDT 2005
jwaixs (04.07.2005 10:04):
> arg... I've lost 1.5 hours of my precious time to try letting re work
> correcty. There's really not a single good re tutorial or documentation
> I could found!
Did you try this one?
http://www.amk.ca/python/howto/regex/regex.html
>>>>import re
>>>>str = "blabla<python>Re modules sucks!</python>blabla"
>>>>re.search("(<python>)(/python>)", str).group()
>
> Traceback (most recent call last):
> File "<stdin>", line 1, in ?
> AttributeError: 'NoneType' object has no attribute 'group'
RE doesn't find "(<python>)(/python>)" because it isn't in your string.
That's why group fails.
>>> import re
>>> s = "blabla<python>Re module is great!</python>blabla"
>>> re.search("(<python>).*(/python>)", s).group()
'<python>Re module is great!</python>'
Matthias
More information about the Python-list
mailing list