Eff-bot trick of an "alternating" regex, for use with "findall", used this time for whitespace vs. non-whitespace
_re_whitespace_alternate = re.compile(r'[ \t\r\n]+|[^ \t\r\n]+')
__test__['_re_whitespace_alternate'] = r"""
>>> def f(s):
... return _re_whitespace_alternate.findall(s)
>>> f(' hello ')
[' ', 'hello', ' ']
>>> f(' \t hello hello \t ')
[' \t ', 'hello', ' ', 'hello', ' \t ']
"""
Join Now to Reply!
To add your own reply, sign in or join Pownce today!