公告
财富商城
积分规则
提问
发文
2020-02-01 06:59发布
甜甜的少女心
Lets Say we have Zaptoit:685158:zaptoit@hotmail.com
Zaptoit:685158:zaptoit@hotmail.com
How do you split so it only be left 685158:zaptoit@hotmail.com
685158:zaptoit@hotmail.com
Following splits the string, ignores first element and rejoins the rest:
":".join(x.split(":")[1:])
Output:
'685158:zaptoit@hotmail.com'
s = re.sub('^.*?:', '', s)
>>> s = 'Zaptoit:685158:zaptoit@hotmail.com' >>> s.split( ':', 1 )[1] '685158:zaptoit@hotmail.com'
Another solution:
s = 'Zaptoit:685158:zaptoit@hotmail.com' s.split(':', 1)[1]
As of Python 2.5 there is an even more direct solution. It degrades nicely if the separator is not found:
>>> s = 'Zaptoit:685158:zaptoit@hotmail.com' >>> s.partition(':') ('Zaptoit', ':', '685158:zaptoit@hotmail.com') >>> s.partition(':')[2] '685158:zaptoit@hotmail.com' >>> s.partition(';') ('Zaptoit:685158:zaptoit@hotmail.com', '', '')
Use the method str.split() with the value of maxsplit argument as 1.
mailID = 'Zaptoit:685158:zaptoit@hotmail.com' mailID.split(':', 1)[1]
Hope it helped.
最多设置5个标签!
Following splits the string, ignores first element and rejoins the rest:
Output:
Another solution:
As of Python 2.5 there is an even more direct solution. It degrades nicely if the separator is not found:
Use the method str.split() with the value of maxsplit argument as 1.
Hope it helped.