Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #75860
| Path | csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!feeds.phibee-telecom.net!newsfeed.xs4all.nl!newsfeed1a.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <python-python-list@m.gmane.org> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.004 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'else:': 0.03; 'none:': 0.07; 'received:80.91': 0.09; 'received:80.91.229': 0.09; 'received:gmane.org': 0.09; 'received:list': 0.09; 'subject:string': 0.09; '"/"': 0.16; 'parts.': 0.16; 'received:80.91.229.3': 0.16; 'received:97': 0.16; 'received:plane.gmane.org': 0.16; 'regex,': 0.16; 'subject:simple': 0.16; 'tuple': 0.16; 'skip:= 10': 0.16; 'wrote:': 0.18; 'import': 0.22; 'header:User-Agent:1': 0.23; 'this:': 0.26; 'skip:" 20': 0.27; 'header:X-Complaints-To:1': 0.27; 'header:In-Reply-To:1': 0.27; '(this': 0.29; 'usually': 0.31; 'this.': 0.32; 'says': 0.33; 'subject:the': 0.34; 'but': 0.35; 'there': 0.35; 'christopher': 0.36; 'from:addr:live.com': 0.36; 'subject:?': 0.36; 'skip:[ 10': 0.38; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'skip:p 20': 0.39; 'received:org': 0.40; 'skip:x 10': 0.40; 'simple': 0.61; "you're": 0.61; 'for:': 0.64; 'subject:more': 0.64; 'more': 0.64; 'different': 0.65; 'results': 0.69 |
| X-Injected-Via-Gmane | http://gmane.org/ |
| To | python-list@python.org |
| From | Christopher Welborn <cjwelborn@live.com> |
| Subject | Re: more simple to split the string? |
| Date | Thu, 07 Aug 2014 20:29:37 -0500 |
| References | <53E4186A.5020201@gmail.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=utf-8; format=flowed |
| Content-Transfer-Encoding | 8bit |
| X-Gmane-NNTP-Posting-Host | 97-82-32-11.dhcp.mtgm.al.charter.com |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Thunderbird/31.0 |
| In-Reply-To | <53E4186A.5020201@gmail.com> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.15 |
| Precedence | list |
| List-Id | General discussion list for the Python programming language <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.12732.1407461393.18130.python-list@python.org> (permalink) |
| Lines | 35 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1407461393 news.xs4all.nl 2900 [2001:888:2000:d::a6]:33412 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:75860 |
Show key headers only | View raw
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
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: more simple to split the string? Christopher Welborn <cjwelborn@live.com> - 2014-08-07 20:29 -0500
csiph-web