Path: csiph.com!fu-berlin.de!uni-berlin.de!not-for-mail From: Cory Madden 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: 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: 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 List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Xref: csiph.com comp.lang.python:101078 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, 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