python split a string with at least 2 whitespaces

>>> import re    
>>> text="10DEUTSCH        GGS Neue Heide 25-27     Wahn-Heide   -1      -1"
>>> re.split(r'\s{2,}', text)
['10DEUTSCH', 'GGS Neue Heide 25-27', 'Wahn-Heide', '-1', '-1']

Where

  • \s matches any whitespace character, like \t\n\r\f\v and more
  • {2,} is a repetition, meaning “2 or more”

Leave a Comment