2004年03月11日 星期四 17:23
Anthony Liu,ÄúºÃ£¡ | ºÃÏñÊÇre±í´ïʽÖÐʹÓõķûºÅ£¬ÄãÓ¦¸ÃʹÓÃ\|À´×ªÒå ======= 2004-03-11 17:16:30 ÄúÔÚÀ´ÐÅÖÐдµÀ£º======= >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 youre looking for faster >http://search.yahoo.com > >_______________________________________________ >python-chinese list >python-chinese at lists.python.cn >http://python.cn/mailman/listinfo/python-chinese > = = = = = = = = = = = = = = = = = = = = ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡Ö Àñ£¡ ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡zhao ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡bear_sh at eastday.com ¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡¡2004-03-11 -------------- next part -------------- A non-text attachment was scrubbed... Name: fox.gif Type: image/gif Size: 9519 bytes Desc: not available Url : http://lists.exoweb.net/pipermail/python-chinese/attachments/20040311/5c852138/fox.gif
2004年03月11日 星期四 17:26
It's because that some punctuations are special characters, so maybe you should try to use \ to escape special characters, and I also suggest you to use raw string which starts with r instead of normal strings for regular expressions. and this always something wrong with your email encoding,why? >From: Anthony Liu <antonyliu2002 at yahoo.com> >Reply-To: python-chinese at lists.python.cn >To: pycn <python-chinese at lists.python.cn> >Subject: [python-chinese] v # invalid expression ???? >Date: Thu, 11 Mar 2004 01:16:30 -0800 (PST) > >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 youre looking for faster >http://search.yahoo.com >_______________________________________________ >python-chinese list >python-chinese at lists.python.cn >http://python.cn/mailman/listinfo/python-chinese _________________________________________________________________ ÓëÁª»úµÄÅóÓѽøÐн»Á÷£¬ÇëʹÓà MSN Messenger: http://messenger.msn.com/cn
2004年03月11日 星期四 18:10
是的, 多谢提醒。 --- zhao <bear_sh at eastday.com> wrote: > Anthony Liu,您好! > > | 好像是re表达式中使用的符号,你应该使用\|来转义 > > ======= 2004-03-11 17:16:30 您在来信中写道:======= > > >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抮e looking for faster > >http://search.yahoo.com > > > >_______________________________________________ > >python-chinese list > >python-chinese at lists.python.cn > >http://python.cn/mailman/listinfo/python-chinese > > > > = = = = = = = = = = = = = = = = = = = = > > > 致 > 礼! > > > zhao > bear_sh at eastday.com > 2004-03-11 > > > ATTACHMENT part 2 image/gif name=fox.gif > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese > __________________________________ Do you Yahoo!? Yahoo! Search - Find what youre looking for faster http://search.yahoo.com
2004年03月11日 星期四 18:11
Yes, Who, exactly that is the case. It works now. Thanks a lot. --- Who Bruce <whoonline at msn.com> wrote: > It's because that some punctuations are special > characters, so maybe you > should try to use \ to escape special characters, > and I also suggest you to > use raw string which starts with r instead of normal > strings for regular > expressions. > > and this always something wrong with your email > encoding,why? > > >From: Anthony Liu <antonyliu2002 at yahoo.com> > >Reply-To: python-chinese at lists.python.cn > >To: pycn <python-chinese at lists.python.cn> > >Subject: [python-chinese] v # invalid expression > ???? > >Date: Thu, 11 Mar 2004 01:16:30 -0800 (PST) > > > >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抮e looking for faster > >http://search.yahoo.com > >_______________________________________________ > >python-chinese list > >python-chinese at lists.python.cn > >http://python.cn/mailman/listinfo/python-chinese > > _________________________________________________________________ > 与联机的朋友进行交流,请使用 MSN Messenger: > http://messenger.msn.com/cn > > _______________________________________________ > python-chinese list > python-chinese at lists.python.cn > http://python.cn/mailman/listinfo/python-chinese __________________________________ Do you Yahoo!? Yahoo! Search - Find what youre looking for faster http://search.yahoo.com
Zeuux © 2024
京ICP备05028076号