Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #101078
| Path | csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail |
|---|---|
| From | Cory Madden <csmadden@gmail.com> |
| Newsgroups | comp.lang.python |
| Subject | Re: Newbie: Check first two non-whitespace characters |
| Date | Thu, 31 Dec 2015 10:56:05 -0800 |
| Lines | 16 |
| Message-ID | <mailman.120.1451590313.11925.python-list@python.org> (permalink) |
| References | <240ab049-68a0-4a00-b911-d58cae9bfbcf@googlegroups.com> |
| Mime-Version | 1.0 |
| Content-Type | text/plain; charset=UTF-8 |
| X-Trace | news.uni-berlin.de Dtm2dtQDpTyZ0nPuPRdJQAYWji2+s+UaW7lhMRQeLyQg== |
| Return-Path | <csmadden@gmail.com> |
| 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; 'ideally': 0.04; 'matches': 0.07; 'subject:two': 0.07; 'cc:addr:python-list': 0.09; 'subject:characters': 0.09; 'thu,': 0.15; 'received:io': 0.16; 'received:psf.io': 0.16; 'subject:non': 0.16; 'wrote:': 0.16; 'string': 0.17; '2015': 0.20; 'cc:2**0': 0.20; 'cc:addr:python.org': 0.20; '31,': 0.22; 'cc:no real name:2**0': 0.22; 'am,': 0.23; 'dec': 0.23; 'header:In-Reply-To:1': 0.24; '(which': 0.26; 'message-id:@mail.gmail.com': 0.27; 'be:': 0.29; 'url:mailman': 0.30; 'url:python': 0.33; 'url:listinfo': 0.34; "skip:' 20": 0.34; 'received:google.com': 0.35; 'could': 0.35; 'something': 0.35; 'but': 0.36; 'should': 0.36; 'url:org': 0.36; 'received:209.85': 0.36; 'subject:: ': 0.37; 'received:209': 0.38; 'subject:-': 0.39; 'url:mail': 0.40; 'space': 0.40; 'personally': 0.61; 'here.': 0.62; 'subject:Check': 0.95 |
| 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 :cc:content-type; bh=WVb1xs9QwXlpMj4lby3YzUM5ylaimyF04+leJyPb/Oc=; b=WAxNejKDyq9d+lq6SGleoR1sl3ZYfI2NhrINqtO7c04XUu908+aD3Gmpi1Vu3CekEU 0+eLA+a5H+uVVbxcDzSWs49Zp0H6tPPf5N2I+JzuNVhaIer1yZkqp1mRaVu9rmuwRguX 3wWrcHNmQcOm+8+H23lqPB6m9i3rh9Uw9X2jxeRoUtYWwe5LUL8v1lgVtdQbolpln0C7 RiegUnu8gwB7XLCjfP44ZBf/+AsJlOQTBXxV8X7lQIe+lasy0rIlrd/+IZzCmtYOMvf1 1NyusoeAN3FpVQDEBFIG9OZGUjzlT7b35WKlZ9xWNYT7UD+3ZNRJhAHQM+0EUdByQQWZ 0G7g== |
| X-Received | by 10.140.154.130 with SMTP id a124mr98909383qha.100.1451588165285; Thu, 31 Dec 2015 10:56:05 -0800 (PST) |
| In-Reply-To | <240ab049-68a0-4a00-b911-d58cae9bfbcf@googlegroups.com> |
| X-Mailman-Approved-At | Thu, 31 Dec 2015 14:31:52 -0500 |
| 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:101078 |
Show key headers only | View raw
I would personally use re here.
test_string = ' [{blah blah blah'
matches = re.findall(r'[^\s]', t)
result = ''.join(matches)[:2]
>> '[{'
On Thu, Dec 31, 2015 at 10:18 AM, <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?
> --
> https://mail.python.org/mailman/listinfo/python-list
Back to comp.lang.python | Previous | Next — Previous in thread | Next 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