Lets Say we have Zaptoit:685158:[email protected]
How do you split so it only be left 685158:[email protected]
Lets Say we have Zaptoit:685158:[email protected]
How do you split so it only be left 685158:[email protected]
>>> s = 'Zaptoit:685158:[email protected]'
>>> s.split( ':', 1 )[1]
'685158:[email protected]'
Another method, without using split:
s = 'Zaptoit:685158:[email protected]'
s[s.find(':')+1:]
Ex:
>>> s = 'Zaptoit:685158:[email protected]'
>>> s[s.find(':')+1:]
'685158:[email protected]'
As of Python 2.5 there is an even more direct solution. It degrades nicely if the separator is not found:
>>> s = 'Zaptoit:685158:[email protected]'
>>> s.partition(':')
('Zaptoit', ':', '685158:[email protected]')
>>> s.partition(':')[2]
'685158:[email protected]'
>>> s.partition(';')
('Zaptoit:685158:[email protected]', '', '')
split(), but hadn't run across partition() before. Thanks!Following splits the string, ignores first element and rejoins the rest:
":".join(x.split(":")[1:])
Output:
'685158:[email protected]'
s = re.sub('^.*?:', '', s)
Use the method str.split() with the value of maxsplit argument as 1.
mailID = 'Zaptoit:685158:[email protected]'
mailID.split(':', 1)[1]
Hope it helped.