Newbie: Check first two non-whitespace characters
Cory Madden
csmadden at gmail.com
Thu Dec 31 13:56:05 EST 2015
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 at 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
More information about the Python-list
mailing list