请问一个正则的问题

classic Classic list List threaded Threaded
7 messages Options
Reply | Threaded
Open this post in threaded view
|

请问一个正则的问题

huang falls
Hello !

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

想将其转成一个list :

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

请问如何做比较合适?

Thanks!

Regards
Falls
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|

Re: 请问一个正则的问题

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

2008/1/17, huang falls <[hidden email]>:
Hello !

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

想将其转成一个list :

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

请问如何做比较合适?

Thanks!

Regards
Falls
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese



--
茫茫人海,你是我的最爱
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|

Re: 请问一个正则的问题

joshua-39
In reply to this post by huang falls
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 [hidden email]
> Subscribe: send subscribe to [hidden email]
> Unsubscribe: send unsubscribe to  [hidden email]
> Detail Info: http://python.cn/mailman/listinfo/python-chinese

_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|

Re: 请问一个正则的问题

nathan.wu
print str[1:-1].split(')(')


> Date: Thu, 17 Jan 2008 15:22:15 +0800
> From: [hidden email]
> To: [hidden email]
> 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 [hidden email]
> > Subscribe: send subscribe to [hidden email]
> > Unsubscribe: send unsubscribe to [hidden email]
> > Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
> _______________________________________________
> python-chinese
> Post: send [hidden email]
> Subscribe: send subscribe to [hidden email]
> Unsubscribe: send unsubscribe to [hidden email]
> Detail Info: http://python.cn/mailman/listinfo/python-chinese



“七件武器,七种完美” 立刻体验!
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|

Re: 请问一个正则的问题

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


2008/1/17 cunheise <[hidden email]>:

>
>  print str[1:-1].split(')(')
>
>
> > Date: Thu, 17 Jan 2008 15:22:15 +0800
> > From: [hidden email]
> > To: [hidden email]
> > 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 [hidden email]
> > > Subscribe: send subscribe to [hidden email]
> > > Unsubscribe: send unsubscribe to [hidden email]
> > > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> >
> > _______________________________________________
> > python-chinese
> > Post: send [hidden email]
> > Subscribe: send subscribe to [hidden email]
> > Unsubscribe: send unsubscribe to [hidden email]
> > Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
>
> ________________________________
> "七件武器,七种完美" 立刻体验!
> _______________________________________________
> python-chinese
> Post: send [hidden email]
> Subscribe: send subscribe to [hidden email]
> Unsubscribe: send unsubscribe to  [hidden email]
> Detail Info: http://python.cn/mailman/listinfo/python-chinese
>
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|

Re: 请问一个正则的问题

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

2008/1/18 shhgs <[hidden email]>:

> "(aaa)(bbb)(ccc)".replace('(', ' ').replace(')', ' ').split()
>
>
> 2008/1/17 cunheise <[hidden email]>:
>
> >
> >  print str[1:-1].split(')(')
> >
> >
> > > Date: Thu, 17 Jan 2008 15:22:15 +0800
> > > From: [hidden email]
> > > To: [hidden email]
> > > 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 [hidden email]
> > > > Subscribe: send subscribe to [hidden email]
> > > > Unsubscribe: send unsubscribe to [hidden email]
> > > > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> > >
> > > _______________________________________________
> > > python-chinese
> > > Post: send [hidden email]
> > > Subscribe: send subscribe to [hidden email]
> > > Unsubscribe: send unsubscribe to [hidden email]
> > > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> >
> >
> > ________________________________
> > "七件武器,七种完美" 立刻体验!
> > _______________________________________________
> > python-chinese
> > Post: send [hidden email]
> > Subscribe: send subscribe to [hidden email]
> > Unsubscribe: send unsubscribe to  [hidden email]
> > Detail Info: http://python.cn/mailman/listinfo/python-chinese
> >
>
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese
Reply | Threaded
Open this post in threaded view
|

Re: 请问一个正则的问题

junyi sun
In reply to this post by huang falls
正则表达式主要靠调试,试一试这个:http://code.google.com/p/qre/


2008/1/17 huang falls <[hidden email]>:
Hello !

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

想将其转成一个list :

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

请问如何做比较合适?

Thanks!

Regards
Falls
_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese


_______________________________________________
python-chinese
Post: send [hidden email]
Subscribe: send subscribe to [hidden email]
Unsubscribe: send unsubscribe to  [hidden email]
Detail Info: http://python.cn/mailman/listinfo/python-chinese