473,378 Members | 1,449 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

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 1499
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Anand Pillai | last post by:
To search a word in a group of words, say a paragraph or a web page, would a string search or a regexp search be faster? The string search would of course be, if str.find(substr) != -1:...
5
by: Lukas Holcik | last post by:
Hi everyone! How can I simply search text for regexps (lets say <a href="(.*?)">(.*?)</a>) and save all URLs(1) and link contents(2) in a dictionary { name : URL}? In a single pass if it could....
0
by: Lee Gillie | last post by:
We have systems built upon shared libraries, which are maintained by a group of programmers. We install these to the GAC on production servers. For saftey, when a programmer uses one of these...
0
by: Chris Croughton | last post by:
I'm trying to use the EXSLT regexp package from http://www.exslt.org/regexp/functions/match/index.html (specifically the match function) with the libxml xltproc (which supports EXSLT), but...
4
by: Jon Maz | last post by:
Hi All, I want to strip the accents off characters in a string so that, for example, the (Spanish) word "práctico" comes out as "practico" - but ignoring case, so that "PRÁCTICO" comes out as...
26
by: Matt Kruse | last post by:
Are there any current browsers that have Javascript support, but not RegExp support? For example, cell phone browsers, blackberrys, or other "minimal" browsers? I know that someone using Netscape...
7
by: arno | last post by:
Hi, I want to search a substring within a string : fonction (str, substr) { if (str.search(substr) != -1) { // do something } }
24
by: John | last post by:
I know this is a very fundamental question. I am still quite confused if the program call stack stack should always grows upwards from the bottom, or the opposite, or doesn't matter?? That means...
4
by: Matt | last post by:
Hello all, I have just discovered (the long way) that using a RegExp object with the 'global' flag set produces inconsistent results when its test() method is executed. I realize that 'global'...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.