Python论坛  - 讨论区

标题:[python-chinese] 请问一个正则的问题

2008年01月17日 星期四 13:16

huang falls falls1977在gmail.com
星期四 一月 17 13:16:03 HKT 2008

Hello !

str="(aaa)(bbb)(ccc)"

想将其转成一个list :

[ "aaa", "bbb", "ccc" ]

请问如何做比较合适?

Thanks!

Regards
Falls

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

2008年01月17日 星期四 13:22

大熊 bearsprite在gmail.com
星期四 一月 17 13:22:07 HKT 2008

p = re.compile('[(](.+?)[)]')
a = "(aaa)(bbb)(ccc)"
print p.findall(a)
>>['aaa', 'bbb', 'ccc']

2008/1/17, huang falls <falls1977在gmail.com>:
>
> Hello !
>
> str="(aaa)(bbb)(ccc)"
>
> 想将其转成一个list :
>
> [ "aaa", "bbb", "ccc" ]
>
> 请问如何做比较合适?
>
> Thanks!
>
> Regards
> Falls
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese




-- 
茫茫人海,你是我的最爱
-------------- 下一部分 --------------
一个HTML附件被移除...
URL: http://python.cn/pipermail/python-chinese/attachments/20080117/bebb6979/attachment.html 

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

2008年01月17日 星期四 15:22

joshua redack在gmail.com
星期四 一月 17 15:22:15 HKT 2008

s[1:len(s)-1].split(')(')
huang falls wrote:
> Hello !
>
> str="(aaa)(bbb)(ccc)"
>
> 想将其转成一个list :
>
> [ "aaa", "bbb", "ccc" ]
>
> 请问如何做比较合适?
>
> Thanks!
>
> Regards
> Falls
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese


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

2008年01月17日 星期四 15:44

cunheise cunheise在hotmail.com
星期四 一月 17 15:44:22 HKT 2008

print str[1:-1].split(')(')
> Date: Thu, 17 Jan 2008 15:22:15 +0800> From: redack在gmail.com> To: python-chinese在lists.python.cn> Subject: Re: [python-chinese] ÇëÎÊÒ»¸öÕýÔòµÄÎÊÌâ> > s[1:len(s)-1].split(')(')> huang falls wrote:> > Hello £¡> >> > str="(aaa)(bbb)(ccc)"> >> > Ï뽫Æäת³ÉÒ»¸ölist :> >> > [ "aaa", "bbb", "ccc" ]> >> > ÇëÎÊÈçºÎ×ö±È½ÏºÏÊÊ£¿> >> > Thanks!> >> > Regards> > Falls> > _______________________________________________> > python-chinese> > Post: send python-chinese在lists.python.cn> > Subscribe: send subscribe to python-chinese-request在lists.python.cn> > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn> > Detail Info: http://python.cn/mailman/listinfo/python-chinese> > _______________________________________________> python-chinese> Post: send python-chinese在lists.python.cn> Subscribe: send subscribe to python-chinese-request在lists.python.cn> Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn> Detail Info: http://python.cn/mailman/listinfo/python-chinese
_________________________________________________________________
MSNÊ¥µ®ÀñÎï»ðÈȵdz¡£¬Ãâ·Ñ·¢·ÅÖУ¬¿ìÀ´ÁìÈ¡°É£¡
http://im.live.cn/emoticons/?ID=18
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20080117/0cda739f/attachment.htm 

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

2008年01月19日 星期六 07:46

shhgs shhgs.efhilt在gmail.com
星期六 一月 19 07:46:22 HKT 2008

"(aaa)(bbb)(ccc)".replace('(', ' ').replace(')', ' ').split()


2008/1/17 cunheise <cunheise在hotmail.com>:
>
>  print str[1:-1].split(')(')
>
>
> > Date: Thu, 17 Jan 2008 15:22:15 +0800
> > From: redack在gmail.com
> > To: python-chinese在lists.python.cn
> > Subject: Re: [python-chinese] 请问一个正则的问题
>
>
> >
> > s[1:len(s)-1].split(')(')
> > huang falls wrote:
> > > Hello !
> > >
> > > str="(aaa)(bbb)(ccc)"
> > >
> > > 想将其转成一个list :
> > >
> > > [ "aaa", "bbb", "ccc" ]
> > >
> > > 请问如何做比较合适?
> > >
> > > Thanks!
> > >
> > > Regards
> > > Falls
> > > _______________________________________________
> > > python-chinese
> > > Post: send python-chinese在lists.python.cn
> > > Subscribe: send subscribe to python-chinese-request在lists.python.cn
> > > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn
> > > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> >
> > _______________________________________________
> > python-chinese
> > Post: send python-chinese在lists.python.cn
> > Subscribe: send subscribe to python-chinese-request在lists.python.cn
> > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn
> > Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>
> ________________________________
> "七件武器,七种完美" 立刻体验!
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>

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

2008年01月19日 星期六 07:47

shhgs shhgs.efhilt在gmail.com
星期六 一月 19 07:47:34 HKT 2008

顺便说一句,不要用str作变量名。这是py的一个内置函数的名字。

2008/1/18 shhgs <shhgs.efhilt在gmail.com>:
> "(aaa)(bbb)(ccc)".replace('(', ' ').replace(')', ' ').split()
>
>
> 2008/1/17 cunheise <cunheise在hotmail.com>:
>
> >
> >  print str[1:-1].split(')(')
> >
> >
> > > Date: Thu, 17 Jan 2008 15:22:15 +0800
> > > From: redack在gmail.com
> > > To: python-chinese在lists.python.cn
> > > Subject: Re: [python-chinese] 请问一个正则的问题
> >
> >
> > >
> > > s[1:len(s)-1].split(')(')
> > > huang falls wrote:
> > > > Hello !
> > > >
> > > > str="(aaa)(bbb)(ccc)"
> > > >
> > > > 想将其转成一个list :
> > > >
> > > > [ "aaa", "bbb", "ccc" ]
> > > >
> > > > 请问如何做比较合适?
> > > >
> > > > Thanks!
> > > >
> > > > Regards
> > > > Falls
> > > > _______________________________________________
> > > > python-chinese
> > > > Post: send python-chinese在lists.python.cn
> > > > Subscribe: send subscribe to python-chinese-request在lists.python.cn
> > > > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn
> > > > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> > >
> > > _______________________________________________
> > > python-chinese
> > > Post: send python-chinese在lists.python.cn
> > > Subscribe: send subscribe to python-chinese-request在lists.python.cn
> > > Unsubscribe: send unsubscribe to python-chinese-request在lists.python.cn
> > > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> >
> >
> > ________________________________
> > "七件武器,七种完美" 立刻体验!
> > _______________________________________________
> > python-chinese
> > Post: send python-chinese在lists.python.cn
> > Subscribe: send subscribe to python-chinese-request在lists.python.cn
> > Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> >
>

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

2008年01月19日 星期六 19:45

junyi sun ccnusjy在gmail.com
星期六 一月 19 19:45:36 HKT 2008

ÕýÔò±í´ïʽÖ÷Òª¿¿µ÷ÊÔ£¬ÊÔÒ»ÊÔÕâ¸ö£ºhttp://code.google.com/p/qre/


2008/1/17 huang falls <falls1977在gmail.com>:

> Hello £¡
>
> str="(aaa)(bbb)(ccc)"
>
> Ï뽫Æäת³ÉÒ»¸ölist :
>
> [ "aaa", "bbb", "ccc" ]
>
> ÇëÎÊÈçºÎ×ö±È½ÏºÏÊÊ£¿
>
> Thanks!
>
> Regards
> Falls
> _______________________________________________
> python-chinese
> Post: send python-chinese在lists.python.cn
> Subscribe: send subscribe to python-chinese-request在lists.python.cn
> Unsubscribe: send unsubscribe to  python-chinese-request在lists.python.cn
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
-------------- 下一部分 --------------
Ò»¸öHTML¸½¼þ±»ÒƳý...
URL: http://python.cn/pipermail/python-chinese/attachments/20080119/294c4a29/attachment.html 

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

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

    你的回复:

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

    Zeuux © 2024

    京ICP备05028076号