471,892 Members | 2,095 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,892 software developers and data experts.

regexp upward compatibility bug ?


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

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


Jul 18 '05 #1
2 1465
The problem is the use of '-' in the character groups, like

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.

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

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


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


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

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
reply views Thread by YellowAndGreen | last post: by
reply views Thread by zermasroor | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.