Enable Javascript in your browser and then refresh this page, for a much enhanced experience.
re: [Quite documented] solution in Clear category for First Word (simplified) by ale1ster
import re
def first_word(txt):
try:
return re.fullmatch(r'''(?x) (?# Verbose pattern )
^ (?# Match start of string)
\b (?# Match 0-width word boundary assertion )
(?P \w+ ) (?# Match the first word and capture under name 'word' )
\b
.* (?# Match anything else)
$ (?# Match end of string)
''', txt).group('word')
except AttributeError:
# re.Match.group() can fail if there was no match (not in this case though)
return None
Nov. 9, 2019