Search
 
SCRIPT & CODE EXAMPLE
 

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.
Comment

PREVIOUS NEXT
Code Example
Python :: new working version of linkchecker 
Python :: what is actually better duracell or energizer 
Python :: native bold text 
Python :: how to change cursor on hover of button in tkinter 
Python :: text to speech to specific language python 
Python :: resize multiple images to same size python 
Python :: how to insert a placeholder text in django modelform 
Python :: pygame flip image 
Python :: is root node an internal node 
Python :: python get weather temperature 
Python :: text to dictionary python 
Python :: kaaba python tutorial 
Python :: how to add card using py-trello API 
Python :: when pyspark 
Python :: write specific columns to csv pandas 
Python :: all permutations python 
Python :: how to add scrollbar to listbox in tkinter 
Python :: drawkeypoints cv2 
Python :: django run queryset in terminal 
Python :: generate random integer matrix python 
Python :: add button to streamlit 
Python :: export sklearn.metrics.classification_report as csv 
Python :: scientific notation to decimal python 
Python :: print last n rows of dataframe 
Python :: python discord how to get user variables 
Python :: how to clear command prompt python 
Python :: number pyramid pattern in python 
Python :: python every other including first 
Python :: python get pixel color 
Python :: union df pandas 
ADD CONTENT
Topic
Content
Source link
Name
3+2 =