Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #33553
| Path | csiph.com!usenet.pasdenom.info!aioe.org!news.stack.nl!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.011 |
| X-Spam-Evidence | '*H*': 0.98; '*S*': 0.00; 'python.': 0.02; 'assume': 0.11; "skip:' 30": 0.15; 'appreciated!': 0.16; 'exists)': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; 'key/value': 0.16; 'pairs': 0.16; 'python-list,': 0.16; "skip:' 60": 0.16; 'string': 0.17; 'wrote:': 0.17; 'trying': 0.21; 'parse': 0.22; 'posted': 0.22; 'header:In-Reply-To:1': 0.25; 'am,': 0.27; 'message-id:@mail.gmail.com': 0.27; 'separated': 0.29; "i'm": 0.29; 'to:addr:python-list': 0.33; 'received:google.com': 0.34; 'nov': 0.35; 'received:209.85': 0.35; 'received:209': 0.37; 'subject:: ': 0.38; 'to:addr:python.org': 0.39; 'where': 0.40; 'header:Received:5': 0.40; 'most': 0.61; 'effective': 0.63; 'more': 0.63; '20,': 0.65; 'opinions': 0.72; 'convinced': 0.93 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; bh=ph18SZswwJHfohYLHZzA9gAd2jzCsfZ4uGqTRQLkAY0=; b=Q+ykEP2qcKqrqo/JB4Hrdp8X/NscrBfWcg4vUmNZq4+Hvf38WpoB9Vy6zObwudKuuh z43J/LlxFF6ehNaXd24AaGeAUm4G6AJihlWAGZW5Ty/A2esAlJaOcIV3ogG4tnT/oFB4 IsUQfdqzD3ijFDFLQd+1B6kcM7QxuDZIJTVgaehyfQz/2F285WPhMQTocBFUIg6tOUOb wNKSrZKkmI0jvTGn1Axgpwnuv2cq9pVAZBFmVjBmcXfBlLWJa1NuQExCgCioAsm3KmBD ZwGKnoBeYLy3bwl8OmZ7rH6go/q02WKDF9ONIvTdj518pQM5tvCshjxrNQVRM31aJVAC l4/Q== |
| MIME-Version | 1.0 |
| In-Reply-To | <assp.06702d7ae4.92097A6A775D5147B1078E3F15430B92348EA96E@prato.activenetwerx.local> |
| References | <assp.06702d7ae4.92097A6A775D5147B1078E3F15430B92348EA96E@prato.activenetwerx.local> |
| Date | Tue, 20 Nov 2012 07:42:19 +1100 |
| Subject | Re: Robust regex |
| From | Chris Angelico <rosuav@gmail.com> |
| To | python-list@python.org |
| Content-Type | text/plain; charset=ISO-8859-1 |
| 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 | <http://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 | <http://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.9.1353357750.29569.python-list@python.org> (permalink) |
| Lines | 21 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1353357750 news.xs4all.nl 6911 [2001:888:2000:d::a6]:60831 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:33553 |
Show key headers only | View raw
On Tue, Nov 20, 2012 at 7:32 AM, Joseph L. Casale
<jcasale@activenetwerx.com> wrote:
> Trying to robustly parse a string that will have key/value pairs separated
> by three pipes, where each additional key/value (if more than one exists)
> will be delineated by four more pipes.
>
> string = 'key_1|||value_1||||key_2|||value_2'
> regex = '((?:(?!\|\|\|).)+)(?:\|\|\|)((?:(?!\|\|\|).)+)(?:\|\|\|\|)?'
>
> I am not convinced this is the most effective or safest, any opinions would
> be greatly appreciated!
Is regex a requirement? Since you posted this on python-list, I'm
going to assume you're working in Python.
string = 'key_1|||value_1||||key_2|||value_2'
content = dict(map(lambda x: x.split("|||"),string.split("||||")))
--> {'key_1': 'value_1', 'key_2': 'value_2'}
ChrisA
Back to comp.lang.python | Previous | Next | Find similar | Unroll thread
Re: Robust regex Chris Angelico <rosuav@gmail.com> - 2012-11-20 07:42 +1100
csiph-web