Skip to content

Instantly share code, notes, and snippets.

@ZhouYang1993
Created April 19, 2020 22:24
Show Gist options
  • Save ZhouYang1993/fb7a5daae8dadbe6155c316896ebccef to your computer and use it in GitHub Desktop.
Save ZhouYang1993/fb7a5daae8dadbe6155c316896ebccef to your computer and use it in GitHub Desktop.
Regex in Python
>>> 'a b c'.split(' ')
# ['a', 'b', '', '', 'c'] Can't split by consecutive spaces.
>>> re.split(r'\s+', 'a b c')
# ['a', 'b', 'c']
>>> re.split(r'[\s\,]+', 'a,b, c d')
# ['a', 'b', 'c', 'd']
>>> re.split(r'[\s\,\;]+', 'a,b;; c d')
['a', 'b', 'c', 'd']
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment