regexp upward compatibility bug ?

Denis S. Otkidach ods at strana.ru
Thu Jan 29 17:16:44 CET 2004


On Thu, 29 Jan 2004, Gilles Lenfant wrote:

GL>    File "txt2html.py", line 27, in txt2html
GL>      pat =
GL> re.compile(r'((ftp|http)://[\w-]+(?:\.[\w-]+)*(?:/[\w-\.?=]*)
GL> *)')
GL>    File "/usr/local/lib/python2.1/sre.py", line 90, in
GL> compile
GL>      return _compile(pattern, flags)
GL>    File "/usr/local/lib/python2.1/sre.py", line 136, in
GL> _compile
GL>      raise error, v # invalid expression
GL> sre_constants.error: bad character range

The problem is in "[\w-\.?=]". "\w" is not a character, so it
cannot be a start of range.  Put "-" at the start or end of
group:

>>> re.compile(r'((ftp|http)://[\w-]+(?:\.[\w-]+)*(?:/[-\w\.?=]*)*)')
<_sre.SRE_Pattern object at 0x40277110>
>>> re.compile(r'((ftp|http)://[\w-]+(?:\.[\w-]+)*(?:/[\w\.?=-]*)*)')
<_sre.SRE_Pattern object at 0x402777a0>


-- 
Denis S. Otkidach
http://www.python.ru/      [ru]





More information about the Python-list mailing list