Newbie question: strange Re behaviour

Patrick.Bussi at space.alcatel.fr Patrick.Bussi at space.alcatel.fr
Mon Apr 15 11:00:25 EDT 2002


Could someone help me understand what's wrong with this very simple regex, whose
initial purpose was to extract the value of an HTML field. For demonstration, I
have oversimplified the code below:

-----start-----
[pat]$ python
Python 2.0 (#1, Apr 11 2001, 19:18:08)
[GCC 2.96 20000731 (Linux-Mandrake 8.0 2.96-0.48mdk)] on linux-i386
Type "copyright", "credits" or "license" for more information.
>>>
>>> import re
>>> s='[^value=].*[^>]'
>>> T='value=baa>'
>>> re.compile(s).search(T).group()
'baa'
>>> T='value=aba>'
>>> re.compile(s).search(T).group()
'ba'
>>> T='value=aab>'
>>> re.compile(s).search(T).group()
Traceback (most recent call last):
  File "<stdin>", line 1, in ?
AttributeError: 'None' object has no attribute 'group'
>>> T='value=bba>'
>>> re.compile(s).search(T).group()
'bba'
-----end -----

Therefore, it seems that re.compile is sensitive to a leading 'a' character,
which is hard to believe.

Any help would be appreciated.

Regards.

---
Patrick Bussi
patrick.bussi at space.alcatel.fr


Any opinions expressed are my own and not necessarily those of my Company.







More information about the Python-list mailing list