Skip to content

Home

String to words

Converts a given string into a list of words.

import re

def words(s, pattern = '[a-zA-Z-]+'):
  return re.findall(pattern, s)

words('I love Python!!') # ['I', 'love', 'Python']
words('python, javaScript & coffee') # ['python', 'javaScript', 'coffee']
words('build -q --out one-item', r'\b[a-zA-Z-]+\b')
# ['build', 'q', 'out', 'one-item']

More like this

Start typing a keyphrase to see matching snippets.