f*cking re module

Erik Max Francis max at alcyone.com
Mon Jul 4 04:10:15 EDT 2005


jwaixs wrote:

> 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! There are only reference, and if you don't know how a
> module work you won't learn it from a reference!

Then Google for regular expression tutorials, not regular expression 
references.

>>>> 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'
> 
> the only thing I want are the number of places blabla, Re modules
> sucks! and blabla are.

Your question is still not clear.  What you're searching for is 
'<python></python>', which isn't there, so .search returns None, and so 
you get that exception (.group takes an argument, anyway).

-- 
Erik Max Francis && max at alcyone.com && http://www.alcyone.com/max/
San Jose, CA, USA && 37 20 N 121 53 W && AIM erikmaxfrancis
   With such a weapon I could boil the Earth to vapor.
   -- Chmeee



More information about the Python-list mailing list