469,342 Members | 5,299 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,342 developers. It's quick & easy.

regexp upward compatibility bug ?

Hi,

Porting a Zope app from (old) Zope 2.3.3 powered by Python 1.5.2 to a
newer Zope powered by Python 2.1.3, I found a regexp problem :

This does perfectly the job with Python 1.5.2 but raises an exception
with Python 2.1.3. I can't see what's wrong when reading the "re" module
doc.

Any hint welcome

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

Many thanks by advance

--
Gilles

Jul 18 '05 #1
2 1424
The problem is the use of '-' in the character groups, like
r'[\w-]'

Here's what the library reference manual has to say:
[]
Used to indicate a set of characters. Characters can be listed
individually, or a range of characters can be indicated by giving
two characters and separating them by a "-". Special characters are
not active inside sets. For example, [akm$] will match any of the
characters "a", "k", "m", or "$"; [a-z] will match any lowercase
letter, and [a-zA-Z0-9] matches any letter or digit. Character
classes such as \w or \S (defined below) are also acceptable inside
a range. If you want to include a "]" or a "-" inside a set, precede
it with a backslash, or place it as the first character. The pattern
[]] will match ']', for example.
http://www.python.org/doc/current/lib/re-syntax.html

So you may want to write r'[-\w]' or r'[\w\-]' instead, based on my
reading.

The same goes for the later part of the pattern [\w-\.?=].

Jeff

Jul 18 '05 #2
"Jeff Epler" <je****@unpythonic.net> a écrit dans le message de
news:ma**************************************@pyth on.org...
The problem is the use of '-' in the character groups, like
r'[\w-]'
[...]
Jeff


Jeff,

Many thanks for the time you spent for my enlightenments. I fixed the stuff
with your help.

--
Gilles
Jul 18 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Anand Pillai | last post: by
5 posts views Thread by Lukas Holcik | last post: by
reply views Thread by Chris Croughton | last post: by
26 posts views Thread by Matt Kruse | last post: by
7 posts views Thread by arno | last post: by
4 posts views Thread by Matt | last post: by
1 post views Thread by CARIGAR | last post: by
reply views Thread by zhoujie | last post: by
1 post views Thread by Marylou17 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.