473,383 Members | 1,876 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,383 software developers and data experts.

how to match u'\uff00' - u'\uff0f' in re module?

I'm trying to match the characters from u'\uff00' to u'\uff0f'.
the code below and get a TypeError.
p = re.compile(u'\uff00'-u'\uff0f')
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
TypeError: unsupported operand type(s) for -: 'unicode' and 'unicode'
so re module does NOT support this operation
however, is there any alternative way to solve my problem?

Any comments/suggestions much appreciated!

Jul 11 '06 #1
3 1537

yichao.zhang wrote:
I'm trying to match the characters from u'\uff00' to u'\uff0f'.
the code below and get a TypeError.
p = re.compile(u'\uff00'-u'\uff0f')
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
TypeError: unsupported operand type(s) for -: 'unicode' and 'unicode'
so re module does NOT support this operation
however, is there any alternative way to solve my problem?

Any comments/suggestions much appreciated!
re DOES work with unicode, you're just subtracting two unicode stings
as the agrument, which is not defined. Try this:

p = re.compile(u'[\uff00-\uff0f]')

Jul 11 '06 #2
On 11/07/2006 12:32 PM, yichao.zhang wrote:
I'm trying to match the characters from u'\uff00' to u'\uff0f'.
the code below and get a TypeError.
p = re.compile(u'\uff00'-u'\uff0f')
That is not a valid regex. It is an attempt to subtract one unicode char
from another, but this is (correctly) not supported, as the error
message says. re.compile expects a string (8-bit or Unicode).

If you wanted to match ASCII characters from 'A' to 'Z', you wouldn't
put re.compile('A'-'Z'), would you? Well I hope not, I hope you would
use re.compile('[A-Z]') -- does that give you a clue?
Traceback (most recent call last):
File "<interactive input>", line 1, in ?
TypeError: unsupported operand type(s) for -: 'unicode' and 'unicode'
so re module does NOT support this operation
Incorrect conclusion. The argument that you attempted to supply is not a
valid expression and thus not a valid argument for *any* function. It
was intercepted before it got to re.compile. re.compile is innocent.
however, is there any alternative way to solve my problem?

Any comments/suggestions much appreciated!
1. Read the fantastic manual.
2. Learn to understand error messages.
3. Assume the most plausible cause (you stuffed up, not the people who
worked on the re module).

HTH,
John
Jul 11 '06 #3
MacDonald
Thanks!

John
Now I know how silly a question that is !
However I'll be not so silly thanks to your help !
I'll follow your suggestions! That's very nice.

Jul 11 '06 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Kenneth McDonald | last post by:
I'm working on the 0.8 release of my 'rex' module, and would appreciate feedback, suggestions, and criticism as I work towards finalizing the API and feature sets. rex is a module intended to make...
6
by: Matt Wette | last post by:
Over the last few years I have converted from Perl and Scheme to Python. There one task that I do often that is really slick in Perl but escapes me in Python. I read in a text line from a file...
12
by: lothar | last post by:
re: 4.2.1 Regular Expression Syntax http://docs.python.org/lib/re-syntax.html *?, +?, ?? Adding "?" after the qualifier makes it perform the match in non-greedy or minimal fashion; as few...
6
by: blueblueblue2005 | last post by:
Hi, below is the code I copy from c++ tutorial, it is about template specialization, but when I compile, I got error message: error: template-id `module<>' for `int mypair<int>::module()' does...
5
by: jeremy.d.brewer | last post by:
Hi, I'm rather new to Python, and I've just written my first Python C module. I was wondering if some more experience Pythonista would look over what I've written and given me some pointers (or...
0
by: Xah Lee | last post by:
in the regex module re: Note: Match() is not exactly equivalent to Search() with "^". For example: re.search(r'^B', 'A\nB',re.M) # succeeds re.match(r'B', 'A\nB',re.M) # fails if without...
11
by: Steve | last post by:
Hi All, I'm having a tough time converting the following regex.compile patterns into the new re.compile format. There is also a differences in the regsub.sub() vs. re.sub() Could anyone lend...
12
by: Johnny Williams | last post by:
I'm struggling to create a regular expression for use with VB .Net which matches a person's name in a string of words. For example in "physicist Albert Einstein was born in Germany and" I want...
10
by: wo_shi_big_stomach | last post by:
Newbie to python writing a script to recurse a directory tree and delete the first line of a file if it contains a given string. I get the same error on a Mac running OS X 10.4.8 and FreeBSD 6.1. ...
24
by: Joe Salmeri | last post by:
I just upgraded from Python 2.4.2 to Python 2.5.1 and have found some unexpected behavior that appears to be a bug in the os.stat module. My OS is Windows XP SP2 + all updates. I have several...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
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
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.