Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
RegEx FTW solution in Clear category for First Word by leggewie
# Explanation
# findall returns a list of all the matches so we need to append [0] to return only the first
# \b matches a word boundary
# [\w'] matches any word character or '
# [\w']+ is a greedy match for an uninterrupted sequence of word characters or '
import re
def first_word(text: str) -> str:
"""
returns the first word in a given text.
"""
return re.findall(r"\b[\w']+\b", text)[0]
May 23, 2021
Comments: