I'm doing practice problems for regular expressions on W3schools and I am supposed to determine if there is a word at the beginning of a string. I don't understand why this code is not working.
def word_at_begin(string):
if bool(re.search(r'^\w+',string)):
return True
else:
return False
wordatbegin = "76858 is a word at the beginning of this string"
word_at_begin(wordatbegin)
The above returns True, and I cannot figure out why. To my knowledge, my code is asking for 1 or more characters at the beginning of the string.