Python论坛  - 讨论区

标题:[python-chinese] v # invalid expression ????

2004年03月11日 星期四 17:16

Anthony Liu antonyliu2002 at yahoo.com
Thu Mar 11 17:16:30 HKT 2004

I am trying to split a string like so:

re.split(',|。|、|!|:|,|?|“|”|)|(|;',
my_string)

Python complains like so:

Traceback (most recent call last):
  File "C:\Python23\codes\regextest.py", line 27, in
-toplevel-
    ultimate =
re.split(',|。|、|!|:|,|?|“|”|)|(|;',
ch[0])
  File "c:\python23\lib\sre.py", line 156, in split
    return _compile(pattern, 0).split(string,
maxsplit)
  File "c:\python23\lib\sre.py", line 229, in _compile
    raise error, v # invalid expression
error: nothing to repeat

Does this mean that the regular expression I pass to
the split function is not valid?

That expression is just like ',|)|#|!', that is, an
or-ed list of punctuations. Then why invalid?



__________________________________
Do you Yahoo!?
Yahoo! Search - Find what you’re looking for faster
http://search.yahoo.com


[导入自Mailman归档:http://www.zeuux.org/pipermail/zeuux-python]

如下红色区域有误,请重新填写。

    你的回复:

    请 登录 后回复。还没有在Zeuux哲思注册吗?现在 注册 !

    Zeuux © 2024

    京ICP备05028076号