Session Ready
Exercise

Entity extraction with regex

Now you'll use another simple method, this time for finding a person's name in a sentence, such as "hello, my name is David Copperfield".

You'll look for the keywords "name" or "call(ed)", and find capitalized words using regex and assume those are names. Your job in this exercise is to define a find_name() function to do this.

Instructions
100 XP
  • Use re.compile() to create a pattern for checking if "name" or "call" keywords occur.
  • Create a pattern for finding capitalized words.
  • Use the .findall() method on name_pattern to retrieve all matching words in message.
  • Call your find_name() function inside respond() and then hit 'Submit Answer' to see how the bot responds to the provided messages.