You can download this code by clicking the button below.
This code is now available for download.
This function takes a string as input, uses regular expressions to find all words, and then returns the longest word.
Technology Stack : Regular expressions (re), max
Code Type : Function
Code Difficulty : Intermediate
import math
import re
def find_longest_word(text):
words = re.findall(r'\b\w+\b', text)
longest_word = max(words, key=len)
return longest_word