By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,548 Members | 1,487 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,548 IT Pros & Developers. It's quick & easy.

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

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a

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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.