On 08/07/2014 07:23 PM, elearn wrote:
str='(\\HasNoChildren \\Junk) "/" "[Gmail]/&V4NXPpCuTvY-"'
x=str.split(' "')
[i.replace('"','') for i in x]
['(\\HasNoChildren \\Junk)', '/', '[Gmail]/&V4NXPpCuTvY-']
x.strip(" ") will create four parts.
is there more simple to do that ?
There are many different ways to do this. I don't usually
recommend regex, but I thought I would present you with this:
import re
s ='(\\HasNoChildren \\Junk) "/" "[Gmail]/&V4NXPpCuTvY-"'
partpat = re.compile(r'(\(.+\)) "(.+)" "(.+)"')
partsmatch = partpat.search(s)
if partsmatch is None:
print('No matches.')
else:
print(partsmatch.groups())
# Results (a Tuple of strings):
('(\\HasNoChildren \\Junk)', '/', '[Gmail]/&V4NXPpCuTvY-')
The pattern says you're looking for: (this thing) "this" "this"
--
\¯\ /¯/\
\ \/¯¯\/ / / Christopher Welborn (cj)
\__/\__/ / cjwelborn at live·com
\__/\__/ http://welbornprod.com
--
https://mail.python.org/mailman/listinfo/python-list