Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #101101
| Path | csiph.com!news.mixmin.net!newsreader4.netcologne.de!news.netcologne.de!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Karim <kliateni@gmail.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: Newbie: Check first two non-whitespace characters |
| Date | Fri, 1 Jan 2016 10:43:39 +0100 |
| Lines | 43 |
| Message-ID | <mailman.136.1451641422.11925.python-list@python.org> (permalink) |
| References | <240ab049-68a0-4a00-b911-d58cae9bfbcf@googlegroups.com> <568579DF.50805@gmail.com> <n64dik$qo4$1@ger.gmane.org> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=windows-1252; format=flowed |
| Content-Transfer-Encoding | 7bit |
| X-Trace | news.uni-berlin.de k0mDw1ZmaTfUWoT3T+ysIgiYaPnbkD40ymRsh6ygOMTg== |
| Return-Path | <kliateni@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.051 |
| X-Spam-Evidence | '*H*': 0.90; '*S*': 0.00; 'ideally': 0.04; 'subject:two': 0.07; 'subject:characters': 0.09; 'build.': 0.16; 'forward:': 0.16; 'received:192.168.43': 0.16; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:non': 0.16; 'wrote:': 0.16; 'string': 0.17; '>>>': 0.20; 'to:2**1': 0.21; 'doc': 0.22; 'lawrence': 0.22; 'parser': 0.22; 'import': 0.24; 'header:In- Reply-To:1': 0.24; "i've": 0.25; 'header:User-Agent:1': 0.26; '(which': 0.26; 'be:': 0.29; 'depth': 0.29; 'pile': 0.29; 'print': 0.30; 'message-id:@gmail.com': 0.34; 'received:google.com': 0.35; 'could': 0.35; 'something': 0.35; 'received:74.125.82': 0.35; 'but': 0.36; 'should': 0.36; 'tool': 0.36; 'to:addr:python-list': 0.36; 'subject:: ': 0.37; 'list.': 0.37; 'received:192': 0.39; 'subject:-': 0.39; 'to:addr:python.org': 0.40; 'mark': 0.40; 'space': 0.40; 'ever': 0.60; 'your': 0.60; "you'll": 0.61; 'hope': 0.61; 'email addr:gmail.com': 0.62; 'charset:windows-1252': 0.62; 'introduction': 0.63; 'more': 0.63; 'intent': 0.66; 'received:74.125.82.47': 0.84; 'seen.': 0.84; 'to:addr:yahoo.co.uk': 0.84; 'subject:Check': 0.95 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-type:content-transfer-encoding; bh=fRxfzWW447mukiFnjgjfDSdZBIcXGyHbjBm4b9vfCPw=; b=TJMseuvLqH1mf82Oc7TtX1PS8wVjwzYqUMv3lRuvTs0fM+TfU1u/pxBRJIg06uYXog 1FgnGvLBXOuewUCZgoEqQOOouk3NSOnEJb1pTtRVwc/FVjLB5pyKLMlZCijnCC8A6ctE eNAciWGkWWVqzWT0dJ+VpWMR3GwyklIX0V9UpHVHk6DIgolyDXPs30dCOJm7lZqipDVx RXtmPRBkpoBTN3kLhzAex3WeNWMKVb42Kxc6bUUIfhgZQYCmn//3q6iCW5Psu2WU4lzv IGs+Gs+iKchBwUovj+Dm7rB+JOOi1LPH00BtRhR6A9NkpnsXAr/hMlqilq059XLWUOX/ tttQ== |
| X-Received | by 10.28.221.85 with SMTP id u82mr73955370wmg.95.1451641421048; Fri, 01 Jan 2016 01:43:41 -0800 (PST) |
| User-Agent | Mozilla/5.0 (X11; Linux x86_64; rv:38.0) Gecko/20100101 Thunderbird/38.4.0 |
| In-Reply-To | <n64dik$qo4$1@ger.gmane.org> |
| X-BeenThere | python-list@python.org |
| X-Mailman-Version | 2.1.20+ |
| 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> |
| Xref | csiph.com comp.lang.python:101101 |
Show key headers only | View raw
On 01/01/2016 00:25, Mark Lawrence wrote:
> On 31/12/2015 18:54, Karim wrote:
>>
>>
>> On 31/12/2015 19:18, otaksoftspamtrap@gmail.com wrote:
>>> I need to check a string over which I have no control for the first 2
>>> non-white space characters (which should be '[{').
>>>
>>> The string would ideally be: '[{...' but could also be something like
>>> ' [ { ....'.
>>>
>>> Best to use re and how? Something else?
>>
>> Use pyparsing it is straight forward:
>>
>> >>> from pyparsing import Suppress, restOfLine
>>
>> >>> mystring = Suppress('[') + Suppress('{') + restOfLine
>>
>> >>> result = mystring.parse(' [ { .... I am learning pyparsing' )
>>
>> >>> print result.asList()
>>
>> ['.... I am learning pyparsing']
>>
>> You'll get your string inside the list.
>>
>> Hope this help see pyparsing doc for in depth study.
>>
>> Karim
>
> Congratulations for writing up one of the most overengineered pile of
> cobblers I've ever seen.
>
You welcome !
The intent was to make a simple introduction to pyparsing which is a
powerful tool for more complex parser build.
Karim
Back to comp.lang.python | Previous | Next — Previous in thread | Find similar | Unroll thread
Newbie: Check first two non-whitespace characters otaksoftspamtrap@gmail.com - 2015-12-31 10:18 -0800
Re: Newbie: Check first two non-whitespace characters MRAB <python@mrabarnett.plus.com> - 2015-12-31 18:38 +0000
Re: Newbie: Check first two non-whitespace characters Karim <kliateni@gmail.com> - 2015-12-31 19:54 +0100
Re: Newbie: Check first two non-whitespace characters Karim <kliateni@gmail.com> - 2015-12-31 20:05 +0100
Re: Newbie: Check first two non-whitespace characters cassius.fechter@gmail.com - 2015-12-31 11:21 -0800
Re: Newbie: Check first two non-whitespace characters Cory Madden <csmadden@gmail.com> - 2015-12-31 10:56 -0800
Re: Newbie: Check first two non-whitespace characters Denis McMahon <denismfmcmahon@gmail.com> - 2015-12-31 20:35 +0000
Re: Newbie: Check first two non-whitespace characters Mark Lawrence <breamoreboy@yahoo.co.uk> - 2015-12-31 23:25 +0000
Re: Newbie: Check first two non-whitespace characters Steven D'Aprano <steve@pearwood.info> - 2016-01-01 12:12 +1100
Re: Newbie: Check first two non-whitespace characters Steven D'Aprano <steve@pearwood.info> - 2016-01-01 12:23 +1100
Re: Newbie: Check first two non-whitespace characters Random832 <random832@fastmail.com> - 2015-12-31 20:31 -0500
Re: Newbie: Check first two non-whitespace characters Jussi Piitulainen <harvesting@is.invalid> - 2016-01-01 10:16 +0200
Re: Newbie: Check first two non-whitespace characters Karim <kliateni@gmail.com> - 2016-01-01 10:43 +0100
csiph-web