Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

regex all words longer than n

import re
def long_words(text):
  pattern = r"w{7,}"
  result = re.findall(pattern, text)
  return result

print(long_words("I like to drink coffee in the morning.")) # ['morning']
print(long_words("I also have a taste for hot chocolate in the afternoon.")) # ['chocolate', 'afternoon']
print(long_words("I never drink tea late at night.")) # []

#replace the 7 with any number you want to return words >= to.
 
PREVIOUS NEXT
Tagged: #regex #words #longer
ADD COMMENT
Topic
Name
1+4 =